Front-end performance optimization
1.) Reduce DOM manipulation
- Manipulating the DOM is performance-costly because it causes DOM rearrangement (reflow) and redrawing
- Frameworks like VUE/REACT don’t require DOM manipulation (recommended)
- Reading and writing separation
- Batch DOM creation based on document fragments or string concatenation
- Modify styles using transform whenever possible
- To modify styled elements, do so in a separate document flow (layer) whenever possible.
- .
2.) Reduce the number and size of HTTP requests on the page
HTTP has concurrency limits, multiple HTTP requests need to wait for resources to load back before rendering.
- Resource merge & compress (e.g. CSS merge into one, JS merge into one, Sprite graphics…->webpack)
- Lazy loading of images/audio/video [Render the page for the first time, reduce HTTP requests to optimize white screen wait time, request real images when the page is rendered]
- Reduce the size of the image as much as possible, or use a font icon, without compromising the image’s authenticity
- Use inline when CSS code is low
- Open the HTTP
- Enable GZIP compression for the server
- Each step takes some time. BASE64 directly encodes the image, and the browser only needs to render it. Base64 code is too long, which is not convenient for development and maintenance, and also increases the page request time. Therefore, in the project, we will compile and generate Base64 based on Webpack, and do not use it too much.
3) Front-end skeleton screen rendering: client skeleton screen + server skeleton screen render quickly for the first time, reducing the white screen
- SEO Search engine optimization
- SEM Baidu bidding ranking
- Website Alex Rankings
- Key words weight
- Vue :nuxt.js react:next.js
- Server rendering is good for SEO optimization, while client rendering is not
- In the case of “high server concurrency pressure”, server rendering can achieve page rendering faster
- Disadvantages: The server is under too much pressure, and the front and back ends are not completely separated.
- The server only needs to complete the rendering of the first screen information, the rest of the screen or to the client to complete
- Pure front-end skeleton screen scheme
4) Ultimate solution: use CDN
assorted
1) CSS
- The CSS style sheet is placed in the header import to pre-request style resources when rendering the DOM-tree, making the page render faster
- CSS selectors should not be too deep
- Use CSS3 animations whenever possible, or requestAnimationFrame if JS animations are required
- Avoid table layouts
- Reduce the use of filter in the CSS
- Do not use @import to import CSS resources
- Avoid USING CSS expressions