How to better reduce page loading time, 19 methods are provided below, for reference only, interested friends can take a look.
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
{VERHASH} is the characteristic parameter. If this parameter does not change, the cache file will be used. If it changes, the new file will be downloaded again or the information will be updated.
8. Try to use the GET method for Ajax calls
When actually using XMLHttpRequest, if the POST method is used, two HTTP requests will occur, while only one HTTP request will occur using the GET method. . If you use the GET method instead, HTTP requests are reduced by 50%!
9. Develop good development and maintenance habits and try to avoid repeated calls to scripts
10. Reduce the use of iframes and try not to use them if unnecessary
11. Reasonable Using Flush
After the client sends browsing requests, the server generally takes 200-500ms to process these requests. During this period, the client browser is in a waiting state. If you want to reduce the user's waiting time, you can Use flush at the appropriate location to push ready content to the client. This is easy to implement in PHP. For example:
e1698f9f8c729d9d3dfb866fa42897e812. Avoid using 301 and 302 redirection
When the browser, When a "crawler" sent by a proxy or search engine makes a request for a page or URL, the web server where the calling page or URL is located will check a file named .htaccess. This file contains instructions on how to handle specific requests and plays a key role in security. Users can modify this file to notify the browser, agent or "crawler" whether the called page is temporarily removed (302 redirect) or permanently removed (301 redirect). We can also implement 301/302 permanent redirects through web hosting services instead of .htaccess' files.
13. Optimize image files
Optimize image files and reduce their size, especially thumbnails. Be sure to generate thumbnails according to size and then call them. Do not use the resize method on the web page. Although the image you see in this way is smaller in appearance, the amount of data loaded has not been reduced at all.
Ordinary images and icons should also be compressed as much as possible. This can be achieved by saving web images, reducing the number of colors, etc.
14. When the page content is large enough, it can be displayed in paging, or loaded after page turning like Taobao.
15. Use multiple domain names to load multiple files and pictures in a web page
Some data indicate that during the web page loading process, IE loads the same domain name at the same time. The maximum number of parallel HTTP requests is 2. If the number of files that a web page needs to load exceeds 2 (usually far more than...), to speed up web page access, it is best to distribute the files to multiple domain names, such as the 19th floor, Its js files use independent domain names. It is said that Baidu has more than 20 image servers.
16. css and javascript should be called externally
If the content of css and js is relatively large, try not to write it into the same page. It is more appropriate to load it externally, because browsing The server itself will cache css and js files.
17. Reduce DCOM elements as much as possible
Reduce the number of various <> elements in the web page as much as possible. For example,