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:
139b42becf78f240c831aebfe8e97a6a
12. 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,
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.
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 of this Website
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
WeChat is one of the mainstream chat tools. We can meet new friends, contact old friends and maintain the friendship between friends through WeChat. Just as there is no such thing as a banquet that never ends, disagreements will inevitably occur when people get along with each other. When a person extremely affects your mood, or you find that your views are inconsistent when you get along, and you can no longer communicate, then we may need to delete WeChat friends. How to delete WeChat friends? The first step to delete WeChat friends: tap [Address Book] on the main WeChat interface; the second step: click on the friend you want to delete and enter [Details]; the third step: click [...] in the upper right corner; Step 4: Click [Delete] below; Step 5: After understanding the page prompts, click [Delete Contact]; Warm
Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.
Colorful motherboards enjoy high popularity and market share in the Chinese domestic market, but some users of Colorful motherboards still don’t know how to enter the bios for settings? In response to this situation, the editor has specially brought you two methods to enter the colorful motherboard bios. Come and try it! Method 1: Use the U disk startup shortcut key to directly enter the U disk installation system. The shortcut key for the Colorful motherboard to start the U disk with one click is ESC or F11. First, use Black Shark Installation Master to create a Black Shark U disk boot disk, and then turn on the computer. When you see the startup screen, continuously press the ESC or F11 key on the keyboard to enter a window for sequential selection of startup items. Move the cursor to the place where "USB" is displayed, and then
Tomato Novel is a very popular novel reading software. We often have new novels and comics to read in Tomato Novel. Every novel and comic is very interesting. Many friends also want to write novels. Earn pocket money and edit the content of the novel you want to write into text. So how do we write the novel in it? My friends don’t know, so let’s go to this site together. Let’s take some time to look at an introduction to how to write a novel. Share the Tomato novel tutorial on how to write a novel. 1. First open the Tomato free novel app on your mobile phone and click on Personal Center - Writer Center. 2. Jump to the Tomato Writer Assistant page - click on Create a new book at the end of the novel.
Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game
A summary of how to obtain Win11 administrator rights. In the Windows 11 operating system, administrator rights are one of the very important permissions that allow users to perform various operations on the system. Sometimes, we may need to obtain administrator rights to complete some operations, such as installing software, modifying system settings, etc. The following summarizes some methods for obtaining Win11 administrator rights, I hope it can help you. 1. Use shortcut keys. In Windows 11 system, you can quickly open the command prompt through shortcut keys.
Detailed explanation of Oracle version query method Oracle is one of the most popular relational database management systems in the world. It provides rich functions and powerful performance and is widely used in enterprises. In the process of database management and development, it is very important to understand the version of the Oracle database. This article will introduce in detail how to query the version information of the Oracle database and give specific code examples. Query the database version of the SQL statement in the Oracle database by executing a simple SQL statement
Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual