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!

I got this question the other day. My first thought is: weird question! Specificity is about selectors, and at-rules are not selectors, so... irrelevant?

Yes, you can, and it doesn't really matter in what order. A CSS preprocessor is not required. It works in regular CSS.

You should for sure be setting far-out cache headers on your assets like CSS and JavaScript (and images and fonts and whatever else). That tells the browser

Many developers write about how to maintain a CSS codebase, yet not a lot of them write about how they measure the quality of that codebase. Sure, we have

Have you ever had a form that needed to accept a short, arbitrary bit of text? Like a name or whatever. That's exactly what is for. There are lots of

I'm so excited to be heading to Zürich, Switzerland for Front Conference (Love that name and URL!). I've never been to Switzerland before, so I'm excited

One of my favorite developments in software development has been the advent of serverless. As a developer who has a tendency to get bogged down in the details

In this post, we’ll be using an ecommerce store demo I built and deployed to Netlify to show how we can make dynamic routes for incoming data. It’s a fairly


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use