When we are optimizing website to speed up, some testing tools will always mind us to reduce the number of HTTP requests. Newbies do not know how to reduce the number of requests, so here we will introduce the method to reduce the number of HTTP requests on the website.
What is an http request?
The HTTP protocol defines how web clients request web pages from web servers, and how servers deliver web pages to clients. The HTTP protocol adopts a request/response model. The client sends a request message to the server, and the request message contains the requested method, URL, protocol version, request header and request data.
We can put it this way. If the browser doesn’t send requests to the server, the server won’t how to transfer the file to your browser for display. The higher the number of requests, the longer it will take to transfer and display those contents. Therefore, we shall find ways to reduce the number of requests and thus increase the speed.
How to check the number of website requests?
Take chrome as an example, open the webpage, right-click and select Inspect (CTRL + SHIFT + I), then click the Network tab on the tool interface that appears, refresh the webpage, and you can see the relevant information.
The way to reduce HTTP request
Merge css and js files
There are a lot of guidance of doing so on Internet. Many cache plugins also have this function.
Note that the small print at the bottom mentions that it is not recommended for sites that already use HTTP/2.
This is also why the css and js compression function is not enabled in my dad’s website notes.
For the difference between HTTP 2.0 and HTTP 1.0, please refer to this article
When you turn on the merging function of css and js, you can use gtmetrix to test, and you can find that the score is significantly improved, but if your website server is already http 2.0, it is not wise to deliberately merge files for high scores.
How to manually reduce the number of http requests
1. Use Image Sprites
This is a css trick, which is to put multiple small images used on your website into one image, and then call it through css code.
As shown in the figure below, a picture can be used for 14 icons, which reduces 13 http requests
2. Delete unnecessary images
We can remove some unnecessary images on the web page, such as the logo at the bottom of the website
3. Reduce the image size
Although reducing the image size will not reduce http requests, it will speed up the loading of images, which in turn increases the speed of website opening.
4. Optimize external images
External images are also a factor in the speed of your website and are also counted in the number of http requests to your website.
For websites with many website comments, disabling the Gravatar avatar is a very good choice.
5. Delete unnecessary files
Some plugins also generate css or js files. If the plugin is not necessary, you can consider deleting the plugin, or integrating the plugin code into the website theme.
6. Lazy loading
Lazy loading means that the only the part that is shown in the explorer windown will be loaded. The WP Rocket cache plugin comes with this function. Other cache plugins also have this function.
7. Add cache time
Some caching plug-ins are able to add an extra browser cache time to load the static resources of your website. When users visit your website once, they will not repeatedly load the static resources that have been cached in the browser from the server when they visit again, which will accelerate the effect. .
8. Ignore irrelevant resources
The Asset Cleanup plugin can help you achieve this function.
What are irrelevant resources?
For example, the contact form is usually only used on the contact page, but its js file will be loaded on the whole site. We can set it to load only on the contact page through Asset Cleanup, which reduces the number of requests.
9. Merge css files
Some small css files, we can merge them into one css, which reduces requests (HTTP2.0 can be omitted)
10. Control the number of pictures in the article
If you insert dozens of pictures into an article, the number of requests cannot be reduced.
Improving website speed is good for user experience and SEO optimization, so if your website is very slow, it is very necessary to optimize website speed. The above is an optimization method for website speed by reducing HTTP requests.