Table of Contents
Why is the page load time important?
3. File size and page size
4. Load all resources at the same time
5. A large number of redirections
Conclusion
Home Web Front-end JS Tutorial 5 common mistakes that affect page load times

5 common mistakes that affect page load times

Jan 30, 2021 am 09:43 AM
javascript Page load time

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.

Why is the page load time important?

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.

    Search Engine Ranking
  • — Page load time is one of the important basis for search engines to rank your website in search results. Therefore, the load time of a web page affects how easy it is for users to find it on the web.
  • Conversion Rate
  • — The faster the page loads, the more engaged the user will be. A slow website will obviously lead to lower conversion rates. If your webpage takes too long to load, executing the Call-To-Action (CTA) will consume a lot of time. During this period, the user's patience and enthusiasm will be worn away, and they will eventually close your website without purchasing your product or Use the services you provide. User Experience — The longer your website takes to load, the more satisfied your users will be. As a result, customer retention and repeat visit rates will be higher.
  • Let’s look at a few examples based on research done by HubSpot:

If Yahoo reduced page load time by 0.4 seconds, traffic could increase by 9%.
  • A page that is 1 second slower could cost Amazon $1.6 billion in lost sales each year.
  • A 2-second delay in Bing searches will result in a 4.3% revenue loss per visitor, a 3.75% decrease in clicks, and a 1.8% decrease in query volume.
  • Based on the data above, you can see how important page load time is to your website.

Factors that affect page loading time and optimization techniques

There are many factors that affect page loading time. Among these errors, I have listed the errors I encountered when building a website. Here are five representative mistakes.

1. A large number of HTTP requests

Every time the browser needs to get a file, page or image from the web server, it will make an HTTP request, after which you can Use the "Network" tab in Chrome's "Developer Tools" to monitor which network requests the application makes, which requests are time-consuming, and other information.

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:

    Merging CSS/JS files
  • — You can try to merge the CSS files with JS files are merged into the same file, which reduces requests and eliminates the need to retrieve multiple files from the server. Since all CSS files are rendered in chunks, reducing CSS files will greatly improve page load times.
  • Content loading on demand
  • — Instead of loading all of your application’s images at once, load them only when needed. This approach is called lazy loading or on-demand loading. When a user arrives on your site, you can load images only when the user scrolls to that specific location, rather than loading them all on click.
  • Enable Browser Cache
  • — Allows caching of static images or website content that does not change frequently. When the user visits the website for the second time, the cache can load this content without sending a new HTTP request to the server. This makes content load faster.
  • The server supports HTTP/2
  • - Using HTTP/2, only one connection needs to be established from the browser to the server to load a website, and multiple requests are allowed at the same time. This is much more efficient than creating a new connection for each resource.
2. Not using a CDN

If your website does not have a CDN enabled, load times will increase when users are physically located far away from the server. These delays become more noticeable with distance and affect all HTTP requests to the server. Using a CDN can improve page load times.

CDN

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.

3. File size and page size

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.

4. Load all resources at the same time

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 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>
Copy after login

The above code says, "Wait for the entire document to load before loading the external defer.js file."

5. A large number of redirections

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:

  • Server-side redirection — Fast and cacheable.
  • Client Redirect — Slow and uncacheable.

Optimize web page load times by avoiding using client-side redirects for your pages while keeping server-side redirects to a minimum.

Conclusion

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement an online speech recognition system using WebSocket and JavaScript How to implement an online speech recognition system using WebSocket and JavaScript Dec 17, 2023 pm 02:54 PM

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

How to implement an online reservation system using WebSocket and JavaScript How to implement an online reservation system using WebSocket and JavaScript Dec 17, 2023 am 09:39 AM

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

How to use JavaScript and WebSocket to implement a real-time online ordering system How to use JavaScript and WebSocket to implement a real-time online ordering system Dec 17, 2023 pm 12:09 PM

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

How to use insertBefore in javascript How to use insertBefore in javascript Nov 24, 2023 am 11:56 AM

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

How to get HTTP status code in JavaScript the easy way How to get HTTP status code in JavaScript the easy way Jan 05, 2024 pm 01:37 PM

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service

See all articles