Home  >  Article  >  Web Front-end  >  How to better reduce page loading time

How to better reduce page loading time

零下一度
零下一度Original
2017-07-17 15:08:582006browse
  1. How to better reduce page loading time, 19 methods are provided below, for reference only, interested friends can take a look.

  2. 1. The number of repeated HTTP requests should be reduced as much as possible

(1) Reduce the number of calls to other pages and files.

 (2) Sprite diagram

2. Place the definition of css style in the header of the file

This setting is suitable for users with slow network or large web page content. The situation is more favorable, and the format information can be maintained while the web page is gradually rendered, without affecting the beauty of the web page.

3. Put Javascript script at the end of the file

4. Compress Javascript and CSS code

5. Use CDN (Content Delivery Network) network acceleration

There are many companies doing CDN acceleration business in China. To put it simply, it is to spread your pictures and videos to places that the CDN network can reach, so that users can download these files nearby when they visit, thereby achieving the purpose of speeding up the network. Doing this , while reducing the load on your own website.

6. Enable gzip compression function on the server
After compressing the files to be transferred and then transferring them to the client and then decompressing them, the amount of data transmitted over the network will be greatly reduced. Apache and Nginx on the server can be enabled directly. You can also use code to directly set the transmission file header and add gzip settings. You can also set it directly from the load balancing device. However, it should be noted that this setting will slightly increase the load on the server. Websites whose server performance is not very good should be carefully considered.

7. Ajax uses cache calling
Ajax calls all use cache calling, and are generally implemented using additional feature parameters. Pay attention to

bfdc08ed36b98ffcfba39093e3eea764 elements in the web page as much as possible. For example, f5d188ed2c074f8b944552db028f98a1 is very redundant, and we can completely use < ;div>replaces it.

18. Avoid using CSS scripts (CSS Expressions)

Sometimes in order to dynamically change css parameters, css expression may be used to achieve this, but this will outweigh the gains and losses and will cause the user browser to The burden is obviously increased, so it is not recommended to do this. If changes are needed, you can use Javascript scripts to achieve it.

19. Add file expiration or cache header

For images and Js script files that are frequently accessed by the same user, you can set the buffering time in Apache or Nginx, such as setting a 24-hour expiration time, so that the user can access the When you visit again after passing this page, the same set of pictures or JS will not be downloaded again, thus reducing HTTP requests, user access speed is obviously improved, and the server load will also be reduced.

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;#Set 30 days expiration
}
location ~ .*\.(js|css)?$
{
expires 1h;#Set 1 hour expiration
}


The above is the detailed content of How to better reduce page loading time. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn