multiple files are merged into one. Reduce the number of http requests and reduce the size of requested resources.
- Use font icons or SVG instead of traditional PNG graphics Font icons and SVG are vector graphics. Zooming in will not deform, and the rendering speed is fast.
- Picture lazy load Reduce the number of requests for http rendering on the first screen of a page ing placeholder maps
- Animation is done in css, not js (try to)
- Using Sprite CSS Sprite Draw a smaller picture of resources on a larger picture iloring with background-position
- static resource distribution using cdn
- Put CSS on top and JS on bottom. ve priority to rendering pages
Code optimization
- Reduce closures in js two。 Reduce DOM operation u don't have to think about it if you use libraries such as react
- Css uses link instead of @ import import is synchronous, link is asynchronous
- Animation uses requestAnimationFrame instead of setInterval
- Delegate using DOM event
- import() code splitting, lazy loading take a look at react-loadable?
Performance optimization of mobile H5 front end
In Mobile, there are three seconds to complete the first screen target, and it takes 3 seconds to load the first screen or use Loading. Based on the average 338KB/s (2.71Mb/s) of the network, the resources of the first screen should not exceed 1014KB.
Loading optimization
- Merge CSS, JavaScript two。 Merge small pictures and use Sprite diagrams
- Cache all cacheable resources
- Use long Cache
- Use external references to CSS, JavaScript
- Compress HTML, CSS, JavaScript
- Enable GZip
- Use the first screen to load
- Use demand loading
- Use scrolling to load
- Load via Media Query twelve。 Add Loading progress bar
- Reduce Cookie
- Avoid redirection
- Load third-party resources asynchronously
CSS optimization
- CSS is written in the head, JavaScript is written in the tail or asynchronously
- Avoid empty src for images and iFrames
- Try to avoid resizing pictures
- Try to avoid using DataURL in pictures.
- Try to avoid writing Stye attributes in HTML tags
- Avoid CSS expressions
- Remove empty CSS rules
- Properly use Display properties
- Do not abuse Float
- Do not abuse Web fonts
- Do not declare too much Font-size twelve。 No units are required when the value is 0
- Standardize various browser prefixes
- Avoid making selectors look like regular expressions
Picture optimization
- Use (CSS3, SVG, IconFont) instead of images two。 Use Srcset
- WebP is better than JPG
- PNG8 is better than GIF
- The first load is not greater than 1014KB (based on the average network speed of 3 seconds Unicom)
- Picture no wider than 640
Script optimization
- Reduce redrawing and backflow two。 Cache Dom selection and calculation
- cache list length
- Try to use event proxies to avoid batch binding events
- Try to use the ID selector
- Use touchstart, touchend instead of click
Rendering optimization
- HTML uses Viewport two。 Reduce Dom nod
- Use CSS3 animation as much as possible
- Make requestAnimationFrame Animation replace setTimeout reasonably
- Appropriate use of Canvas animation
- Touchmove, Scroll event will cause multiple renderings
- Use (CSS3 transitions, CSS3 3D transforms, Opacity, Canvas, WebGL, Video) to trigger GPU rendering