Website front-end performance optimization tutorial and front-end performance optimization tutorial
A series of previous blog posts introduced the database performance optimization on the website background. In fact, the front-end optimization is also very important. When the speed of the database model documents increases, page loading is still slow. At this time, you need to optimize the front-end code of the website.
There are not many tutorials on front-end performance optimization. I finally found a textbook, "high-performance website construction Guide". The following describes how to optimize the front-end performance based on the content of this book.
1. Reduce http requests
This is an important principle for improving front-end performance.
Only one request is allowed.
1. Use an image map
We know that an img tag will send a request to the server to retrieve images. If multiple images are merged into one image, multiple requests can be converted into one request. This is the image map.
The image map corresponds to different events based on the locations clicked by the user, which makes the front-end code more complex and difficult to understand. I personally think it is not feasible.
2. Merge JavaScript and Css files
A script tag or link tag also initiates a request to the server. Therefore, you must reduce the number of times that external files are referenced on the page. Generally, a page is configured with a JS and a CSS.
3. Avoid redirection
Redirection also sends an Http request.
Ii. Use the content publishing network
The system automatically selects the server closest to the user.
Iii. Use Cache
1. Specify the Expire Header
Use Expire to specify cache for components
You can also use Cache-Control: max-age = 315360000 instead.
2. Use external Js and Css files
Built-in js and css are usually not cached.
Iv. Compression Components
Streamline the code. It has Js Code.
The main methods are to delete spaces and replace long variable names with v_1 and v_2.
Tool: gzip
5. Place the CSS file on the top
In this way, the page is loaded and displayed gradually, enhancing the user experience and preventing white screens.
6. Place the JavaScript file at the bottom
Prevent page display from being blocked by the download script.
JavDroider's Blog welcomes criticism and suggestions ~~