Home > Article > Web Front-end > 5 common mistakes that affect page load times
If your website takes a long time to load when users visit it, this article may bring some inspiration to your optimization work. But even if it doesn't help you solve your problem, you can learn what are some common errors that affect website loading time.
The loading time of the page directly affects the user's intuitive experience of the website performance. Some research data shows that once the page loading time exceeds 3 seconds, half of the visiting users will be lost while waiting.
General browsers usually limit the number of HTTP requests issued at the same time to between 4-8. Therefore, when the number of concurrent requests is large, long waiting delays will occur. Research done by Yahoo shows that 80% of your application load time relies on HTTP requests, and reducing the total number of HTTP requests is helpful to speed up page load times.
You can reduce the total number of HTTP requests of the web application in the following ways:
What is it? The full name of CDN is Content Delivery Network, which is content distribution network. CDN is a content distribution network built on the Internet. It relies on edge servers deployed in various places and uses the load balancing, content distribution, scheduling and other functional modules of the central platform to enable users to obtain the content they need nearby.
Using a CDN will enable users to obtain the resources required for a web page from the server closest to their location. Servers in a CDN are distributed in different geographical locations. So using this kind of CDN is one of the effective ways to improve application loading time.
For example, if your web server is located in California, your guest access network topology diagram might look like the following if you deploy a CDN.
Most CDN services have their own network backbone, which allows them to provide higher service quality, lower packet rates and faster traffic than the Internet. Loading speed etc. a bit. The disadvantage is that it is expensive.
Loading large size files from the web server or loading large page sizes will take a lot of time, so it may be in order Fetching several such large files makes page load times longer.
#Enabling compression is a common way to reduce the file size of HTTP requests and improve page load times.
There are two common compression methods:
The first method is Gzip. Gzip can locate similar codes in the file and temporarily replace them to make the file smaller. Currently, most web servers support Gzip compression. Enabling compression on HTML or CSS files can typically save about 50% or 70% on file size, thereby reducing page load times and bandwidth used. You can further reduce page load times by reducing the size of images used in your application.
Another compression solution is called Brotli. According to the official introduction, the compression is 20%~30% higher than gzip, and the execution efficiency is more efficient. I haven’t tested it specifically, so I can’t prove it. You can follow Consider your actual situation.
Loading all HTML, CSS and JS files at the same time will increase the page load time because the page is rendered before all these resources are loaded. The process will be blocked.
Delayed JavaScript loading is a mechanism for loading large JS files after other elements have been loaded. This method ensures that loading of page content is not affected by loading large JS files.
If you have an HTML site, you need to call the external JS file (defer.js) before the 36cc49f0c466276486e50c850b7e4956 tag.
<script type="text/javascript"> function downloadJSAtOnload() { var element = document.createElement("script"); element.src = "defer.js"; document.body.appendChild(element); } if (window.addEventListener) window.addEventListener("load", downloadJSAtOnload, false); else if (window.attachEvent) window.attachEvent("onload", downloadJSAtOnload); else <br> window.onload = downloadJSAtOnload; </script>
The above code says, "Wait for the entire document to load before loading the external defer.js file."
Generally, we use redirection to handle moved or deleted pages to avoid errors when users access them. However, more redirects means more HTTP requests. This can significantly increase page load times. Google recommends that website owners remove redirects to improve load times, especially on mobile-first sites.
You can use a similar website scraping tool to get all the redirect requests in your website. By analyzing this, you can stay on top of and clear out unnecessary redirects.
Generally, redirects are divided into two types:
Optimize web page load times by avoiding using client-side redirects for your pages while keeping server-side redirects to a minimum.
A site with fast execution and loading speed is believed to be beneficial to both webmasters and users. I hope this article can make you think about the page. Be confident enough about the importance of loading times.
If you are thinking about improving your website performance, I have some tools to share with you, such as Google Pagespeed Insights, Pingdom, YSlow, etc. These tools can provide complete reports that give you insight into your website’s shortcomings. Hopefully your website will have a better user experience as well.
Original source: https://blog.bitsrc.io/5-common-mistakes-developers-do-that-affect-page-load-time-5a49b0e46f6b
For more programming-related knowledge, please visit: Introduction to Programming! !
The above is the detailed content of 5 common mistakes that affect page load times. For more information, please follow other related articles on the PHP Chinese website!