Front-end designer --- optimizes page loading speed

Source: Internet
Author: User

I. Optimization from the script:

Delete unnecessary comments in Javascript. concise code optimization is a good habit that must be developed, try not to add the function call directly to the HTML tag <Div onclick = ""> This usage is not recommended. Try to use js to dynamically add, reduce tag contamination, and improve code reusability.

Merge similar JS Code or directly encapsulate it into a function, which improves code reusability and saves the Script Loading time.

Introduce the jquery plug-in lazy load written in Javascript, which can delay loading images on long pages. Images outside the visible area of the browser are not loaded until the user scrolls the page to their location. For example, I use the delayed Loading Function of this image in my blog.

Defer attribute in script

If the defer attribute is added during script writing, the browser does not need to process the script immediately when downloading the script, but continues to download and parse the page, this will improve the download performance.
There are many such cases. For example, you have defined many JavaScript variables, or (. INC) has written a lot of scripts to be processed, so you may wish to add the defer attribute to these scripts to improve performance.

Ii. Optimization starting with HTML tags:

Some default attributes of HTML tags can be omitted. For example, <input type = "text"> you do not need to write them. The default attribute of input is text. For example, <form method = "get"> can be omitted because the default attribute is get.

The complete and accurate definition and declaration of the character set in

Iii. Optimization starting with CSS:

In the CSS style of the label, if the height and width of the IMG label are set in advance, the calculation of the image size will be omitted when the browser loads the page, thus improving the page loading speed.

Directly use CSS tools such as sass and compass to reduce code redundancy.

Integrate CSS code: for example, margin-left: 0px; margin-Right: 10px; margin-top: 20px; write margin: 20px 10px 0 0;

Sprite integrates similar images to reduce the number of page requests to attach images.

Define the image size in advance to reduce the time for calculating the image size during the loading process.

Select an image in the appropriate format: we usually use jpg png or GIF.

 

Front-end designer --- optimizes page loading speed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.