Detailed introduction to Web performance optimization solutions
/* Style Definitions */ table.MsoNormalTable {mso-style-name: ordinary form; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}
Chapter 1Open website slow status analysis
When the company accesses theVIP website deployed in the IDC computer room, it will feel very slow. What causes this? In order to shorten the response time of the page and improve our user experience, we need to know what users spend their time waiting for.
You can track our login page, as shown in the figure belowWe can analyze it from the above picture,
HTMLThe document only accounts for 20% of the total response time, and the other 80% response time is used to download JS, CSS, images, etc. components. Therefore, the WEB front-end has a lot of room for optimization. We will comprehensively consider the two aspects of WEB’s front-end optimization and back-end optimization to give a WEB performance optimization plan. .
Chapter 2
Reduce as much as possible Optimization rules of the front desk 1.HTTP Requests
There are several common methods to effectively reduce
, Request: 1Merge scripts and style files, for example, you can combine multiple CSS files into one , combine multiple JS files into one. 2
、CSS Sprites Use CSS background Related elements to perform absolute positioning of the background image,Combine multiple images a picture. 2.
Use browser cache When users browse different pages of the website, a lot of content is repeated, such as the same JS, CSS, pictures, etc. If we could suggest or even force browsers to cache these files locally, it would significantly reduce the amount of traffic generated by the page, thereby reducing page load times. According to the server-side responseheader, a file has several different levels of cache status for the browser. 1. The server tells the browser not to cache this file and to update the file on the server every time. 2. The server does not give any instructions to the browser. 3. In the last transmission, the server sent Last-Modified or Etag data to the browser. When browsing again, the browser These data will be submitted to the server to verify whether the local version is the latest. If it is the latest, the server will return the 304 code, telling the browser to use the local version directly, otherwise download the new version. Generally speaking, if there are and only static files, the server will give these data. 4. The server forces the browser to cache files and sets an expiration time. Before the cache expires, the browser will directly use the local cache file without any communication with the server. What we have to do is to try to force the browser to the fourth state, especially for JS, CSS, pictures and other changes that are relatively large Fewer files. Use compression components and Firefox browsers support clientGZIP, before transmission, use GZIP to compress and then transmit it to the client. After the client receives it, it will be decompressed by the browser. Although this slightly takes up some CPU of the server and the client, it will change What comes is higher bandwidth utilization. For plain text, the compression rate is quite impressive. If each user saves 50% of bandwidth, then the rented bandwidth can serve twice as many customers and shorten the data transmission time. images and JS The easiest way to preload images is to JavaScript Instantiate a new Image() object, and then pass in the URL of the image to be loaded as a parameter. function preLoadImg(url) {
var img = new Image();
img.src = url;
}
You can preload JS and pictures on the login page
5.Put the script at the bottom
The problems caused by placing the script at the top,
1,Use script , progressive rendering will be blocked for content located below the script
2,Parallel downloads will be blocked while downloading the script
Putting it at the bottom may cause JS errors. When the script is not loaded, the user triggers the script event.
Consider the situation comprehensively.
6.Place the style file at the top of the page
If the style sheet is not loaded, building the rendering tree is a waste. There may be two situations when the style file is placed at the bottom of the page:
1, White screen
2, Flashing of unstyled content
7.Use external JS and CSS
turn the inline JS and CSS into external JS, CSS. Reduce repeated downloading of inline JS and CSS.
8. Split components into multiple domains
Page request analysis A
From input URL
The following5 steps are required to render the page1
.Enter the URL address or click on a link of URL
2. The browser parses the IP address # corresponding to
URLbased on the URL address, combined with DNS ## 3. Send HTTP request
4. Start connecting to the requested server and request related content
5. The browser parses the content returned from the server and displays the page.
The above is basically the basic process of a page from request to implementation. Below we will Analyze this process.
When you enter URL, the browser will know this URLWhat is the corresponding IP? Only by knowing the IP address can the browser prepare to send the request to the specified server. Specifically IP and port number. The browser's DNS parser is responsible for parsing URL into the correct IP address. This parsing process takes time, and during this parsing time period, the browser cannot download anything from the server. Browsers and operating systems provide DNS resolution caching support. After obtaining the IP address, the browser sends a HTTP request to the server. The process is as follows :
1. The browser requests the server to open the connection by sending a TCP packet
2. The server also responds to the client's browser by sending a packet, telling the browser that the connection is open.
3. The browser sends a GET request of HTTP. This request contains a lot of things, such as our common cookie and other headHeader information.
In this way, a request is sent.
After the request is sent, it is the server's business. The server-side program sends the final result to the client.
In fact, the first thing to reach the browser is the documents of html. The so-called documents of html are pure htmlCode does not include any pictures, scripts, CSS, etc. That is, the html structure of the page. Because what is returned at this time is only the html structure of the page. The time it takes for this html document to be sent to the browser is very short, generally accounting for about 10% of the entire response time.
After this, the basic skeleton of the page is in the browser. The next step is the process of the browser parsing the page, which is a step-by-step analysis from top to bottom## The skeleton of #html is gone.
If the img tag is encountered in the html document at this time, the browser will send a HTTP request to this The URL address of the img response is used to obtain the image and then present it. If there are many pictures in the html document, flash, then the browser will request them one by one and then render them. If each picture needs to be requested, then it must be done before The steps mentioned: parse url, open tcp connection, etc. Opening a connection also consumes resources. Just like when we are accessing a database, we try to open as few database connections as possible and use more connections in the connection pool. For the same reason, tcp connections can also be reused. http1.1 proposed the concept of persistent connection (persistent connection), which means that the same HTTP connection can handle multiple requests at the same time, reducing tcpConnection.
When the html skeleton of the page is loaded,the browser begins to parse the tags in the page,from Start analyzing from top to bottom.
The first is the parsing of the head tag. If it is found that there is a JS script to be quoted in head, then The browser begins to request the script at this time, and the parsing process of the entire page stops until the JS request is completed. After that, the page is parsed downwards, such as parsing the body tag. If there is an img tag in body, the browser will request img##. #srcThe corresponding resource, if there are multiple img tags, then the browser will parse them one by one, and the parsing will not wait like JS, Will download concurrently.
The above is the detailed content of Detailed introduction to Web performance optimization solutions. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Introduction to Caddy Caddy is a powerful and highly scalable web server that currently has 38K+ stars on Github. Caddy is written in Go language and can be used for static resource hosting and reverse proxy. Caddy has the following main features: Compared with the complex configuration of Nginx, its original Caddyfile configuration is very simple; it can dynamically modify the configuration through the AdminAPI it provides; it supports automated HTTPS configuration by default, and can automatically apply for HTTPS certificates and configure it; it can be expanded to data Tens of thousands of sites; can be executed anywhere with no additional dependencies; written in Go language, memory safety is more guaranteed. First of all, we install it directly in CentO

Form validation is a very important link in web application development. It can check the validity of the data before submitting the form data to avoid security vulnerabilities and data errors in the application. Form validation for web applications can be easily implemented using Golang. This article will introduce how to use Golang to implement form validation for web applications. 1. Basic elements of form validation Before introducing how to implement form validation, we need to know what the basic elements of form validation are. Form elements: form elements are

Using Jetty7 for Web Server Processing in JavaAPI Development With the development of the Internet, the Web server has become the core part of application development and is also the focus of many enterprises. In order to meet the growing business needs, many developers choose to use Jetty for web server development, and its flexibility and scalability are widely recognized. This article will introduce how to use Jetty7 in JavaAPI development for We

First of all, you will have a doubt, what is frp? Simply put, frp is an intranet penetration tool. After configuring the client, you can access the intranet through the server. Now my server has used nginx as the website, and there is only one port 80. So what should I do if the FRP server also wants to use port 80? After querying, this can be achieved by using nginx's reverse proxy. To add: frps is the server, frpc is the client. Step 1: Modify the nginx.conf configuration file in the server and add the following parameters to http{} in nginx.conf, server{listen80

Face-blocking barrage means that a large number of barrages float by without blocking the person in the video, making it look like they are floating from behind the person. Machine learning has been popular for several years, but many people don’t know that these capabilities can also be run in browsers. This article introduces the practical optimization process in video barrages. At the end of the article, it lists some applicable scenarios for this solution, hoping to open it up. Some ideas. mediapipeDemo (https://google.github.io/mediapipe/) demonstrates the mainstream implementation principle of face-blocking barrage on-demand up upload. The server background calculation extracts the portrait area in the video screen, and converts it into svg storage while the client plays the video. Download svg from the server and combine it with barrage, portrait

Web standards are a set of specifications and guidelines developed by W3C and other related organizations. It includes standardization of HTML, CSS, JavaScript, DOM, Web accessibility and performance optimization. By following these standards, the compatibility of pages can be improved. , accessibility, maintainability and performance. The goal of web standards is to enable web content to be displayed and interacted consistently on different platforms, browsers and devices, providing better user experience and development efficiency.

Cockpit is a web-based graphical interface for Linux servers. It is mainly intended to make managing Linux servers easier for new/expert users. In this article, we will discuss Cockpit access modes and how to switch administrative access to Cockpit from CockpitWebUI. Content Topics: Cockpit Entry Modes Finding the Current Cockpit Access Mode Enable Administrative Access for Cockpit from CockpitWebUI Disabling Administrative Access for Cockpit from CockpitWebUI Conclusion Cockpit Entry Modes The cockpit has two access modes: Restricted Access: This is the default for the cockpit access mode. In this access mode you cannot access the web user from the cockpit

nginx can not only hide version information, but also supports custom web server information. Let’s take a look at the final hidden result. How to achieve it? It’s actually very simple. Please look down 1. Official website to download the latest stable version wgethttp://nginx.org/ download/nginx-1.14.1.tar.gz2 Unzip tar-xfnginx-1.14.1.tar.gzcdnginx-1.14.13 Modify the c file (1) vimsrc/http/ngx_http_header_filter_module.c #Modify line 49 staticu_charngx_http_
