The front-end performance optimization summary

Front-end performance optimization can be divided into two categories namely, level optimization page contains http request and the number of inline script position optimization, the optimization code level optimization operation comprising DOM, CSS selectors image optimization and optimization

Which contains the contents of the front end is rich, including HTML, CSS and JS and pictures and other kinds of resources. So front-end optimization is complex and necessary, in the next article, I will introduce methods to optimize front-end performance, with some reference, we want to help.

Optimization purposes

Optimized purpose is to allow faster page loads, and more responsive to user actions, in order to bring a better user experience for developers can be optimized to reduce the number of page requests, can save resources.

The method of optimizing the front end there are many, it can be divided into two categories, the first category is a page-level optimizations such as the number of http requests, position the optimization inline script, the second class code level optimization in the embodiment Javascript DOM manipulation optimization, CSS selectors optimization, image optimization and HTML structure optimization and so on.

Page level optimization

http number of requests

Http reduce the number of requests is the most important and most effective way, you can reduce http request in the following ways

(1) a reasonable set http cache, cache settings appropriate http request can be greatly reduced. To make resources as much as possible can remain longer in the cache

(2) to simplify the page design from the implementation level, to keep the page simple, reducing the use of resources is the most direct.

(3) resource consolidation and compression, as much as possible of external scripts, style merger, more into one.

(4) CSS Sprites, CSS images by merging, this is a good way to reduce the number of requests

Location inline script

Browser is concurrent requests, while the outer chain blocking script often load Shique other resources, such as before the script is loaded, it is behind the images, style and other scripts in the blocked state until after the script has finished loading will begin loading . If the script is placed more forward position, the entire page loading speed will be affected thereby affecting the user experience. So the script as much as possible next move, to reduce the impact of concurrent downloads

Code-level optimization

DOM operations optimization:

To avoid frequent DOM Document operate directly on, may be used instead of a large classname inline style modifications, complex UI elements, to set the position or absolute Fixed, make use css animations, using the appropriate expression canvas minimize css use, use event delegation

Image optimization

By compressing the picture to play the role of front-end performance optimization

CSS selectors:

Most people think of the browser parses the CSS from left to right, right to left in fact higher resolution efficiency, because the scope of the first to find the id selector basically put a limit.

《转》https://baijiahao.baidu.com/s?id=1628591301581843202&wfr=spider&for=pc

Guess you like

Origin www.cnblogs.com/zhoujuan/p/12084291.html