1. From the user's point of view, optimization can make pages load faster, respond more promptly to user operations, and provide users with a more friendly experience.
2. From the perspective of service providers, optimization can reduce the number of page requests or reduce the bandwidth occupied by requests, which can save considerable resources.
In short, proper optimization can not only improve the user experience of the site but also save considerable resource utilization.
There are many ways of front-end optimization, which can be roughly divided into two categories according to the granularity. The first category is page-level optimization, such as the number of HTTP requests, non-blocking loading of scripts, and location optimization of inline scripts; the second category is code Level optimization, such as DOM operation optimization in Javascript, CSS selector optimization, image optimization, and HTML structure optimization, etc. In addition, for the purpose of increasing the input-output ratio, the various optimization strategies mentioned later are roughly arranged in the order of the input-output ratio from large to small.
Page-level optimization to improve website performance
1. JavaScript compression and module packaging
2. Load resources on demand
3. Use array-ids when using the DOM manipulation library
4. Cache
5. Enable HTTP/2
6. Application performance analysis
7. Use load balancing Solution
8. Consider isomorphism for faster startup time
9. Use index to speed up database queries
10. Use faster translation solution
11. Avoid or minimize the use of JavaScript and CSS to block rendering
12. A suggestion for the future :Use service workers + stream
13. Image coding optimization
How does the browser render the page?
The rendering process is as follows:
1. Parse the HTML file and create a DOM tree.
From top to bottom, any style (link, style) and script (script) will be blocked (the external style does not block the loading of subsequent external scripts).
2. Parse CSS. Priority: browser default settings<user settings<external style<inline style<style style in HTML;
3. Combine CSS and DOM to build a Render Tree
4. Layout and drawing, repaint and reflow
Comments
Post a Comment