Front-end performance optimization method

1.  Reduce the number of http requests

Commonly used to reduce the number of http requests are as follows:

1) Merge pictures. When there are many pictures, they can be combined into a large picture, thereby reducing the number of http requests. Pictures that change frequently may not be suitable, and those with relatively stable changes can be considered. In addition to reducing the number of http requests, merging large images can also make full use of the cache to improve performance.

2) Combine and compress css style sheets and js scripts, their common purpose is to reduce the number of http connections.

3) Remove unnecessary requests. Invalid request connection remaining after developing code or system upgrade.

4) Make full use of the cache. The cache mentioned here is the client-side cache or browser cache. The Expires header information is an important basis for client-side caching. The format is similar to Expires:sun ,20 Dec 2017 23:00:00 GMT . If the current time is less than the time specified by Expires , the browser will directly obtain the relevant data information or html file from the cache. If the current time is greater than the time specified by Expires , the browser will send a request to the server to obtain the relevant data information.

Taking Apache as an example, Expires can be set in the Apache configuration file httpd.conf .

2.  Image optimization

Optimization:

1) Use images in PNG format as much as possible, which are relatively small in size.

2) For pictures of different formats, it is best to optimize them before going online.

3) Lazy loading of images, also known as lazy loading.

3.  Use a CDN

CDN is a content distribution network, which can enable users to obtain the desired content nearby, solve the situation of network congestion, and improve the response speed of users accessing websites.

4.  Enable GZIP

GZIP stands for data compression and is used to compress all text resources transmitted using the Internet . The way to enable GZIP is very simple, just set it in the corresponding web service configuration file. Take Apache as an example, add it in the configuration file httpd.conf .

5.  Optimization of style sheets and JS files

Generally, we put the css style sheet file at the head of the file. For example, put it in the <head> tag, so that the CSS stylesheet can be downloaded as soon as possible. Corresponding to the js script file, generally we put it at the end of the page.

6.  Use a cookie -free domain name

The concept of cookie -free domain name : when sending a request, and also requesting a static image and sending cookies , the server will not use these cookies , that is to say, these cookies are useless, do not send them with the request .

7.  Optimization of front-end code structure

 


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324821334&siteId=291194637