Cookies affect loading speed, so static resource domain names do not use cookies. Additionally, redirection affects the load speed, so the server is set up correctly to avoid redirection. Finally, the non-control of third-party resources affects the loading and display of pages, so third-party resources are loaded asynchronously.
Step two: Script execution optimizations
Improper script handling can block page loading and rendering, so be aware of it when you use it:
· CSS is written in the head, JavaScript is written at the tail or asynchronously.
· avoid empty src such as pictures and IFrame.
Empty src reloads the current page, affecting speed and efficiency.
· try to avoid resetting the image size .
Resetting a picture size means resetting the size of a picture multiple times in a page, CSS, JavaScript, and so on, resetting the size of the picture multiple times can cause multiple redraw of the picture, affecting performance.
· picture try to avoid using Dataurl.
Dataurl image compression algorithm files that do not use images will become larger, and will be decoded and then rendered, loading slow and time-consuming.
Step Three: CSS optimization
Try to avoid writing the style attribute in the HTML tag.
· Avoid CSS expression CSS expression execution need to jump out of the CSS tree rendering, so avoid the CSS expression
· Remove empty CSS rules empty CSS rules increase the size of the CSS file and affect the execution of the CSS tree, so you need to remove the empty CSS rules
· Proper use of the display properties of the display property will affect the rendering of the page, so use a properly (a) Display:inline should not use the width, height, margin, padding, and FLOATB) display: Inline-block should not be used after FLOATC) Display:block should not be used after vertical-alignd) display:table-* should not use the margin or float
· Do not abuse float.
Float is computationally large at render time and minimizes use
· Web fonts are not abused.
Web font needs to download, parse, redraw the current page, minimize use
• Do not declare too many font-size.
Excessive font-size triggers the efficiency of the CSS tree
· A value of 0 does not require any units.
For browser compatibility and performance, do not bring units with a value of 0
• Standardize various browser prefixes .
A) No prefix should be placed in the last
b) CSS animation only use (-webkit-without prefix) two kinds of
c) Other prefixes are-webkit--moz--ms-prefix four, (-o-opera browser instead of blink kernel, so obsolete)
• Avoid making selectors look like regular expressions .
Advanced selector execution takes a long time and is difficult to read and avoids using
Fourth step: JavaScript execution optimizations
• Reduce repainting and reflow .
A) Avoid unnecessary DOM operations
b) try to change class instead of style and use classlist instead of classname
c) Avoid using document.write
d) Reduction of DrawImage
· Cache Dom selection and calculation.
Each time the DOM selection is evaluated, it is cached
· Cache list. length.
Every. Length is calculated, and a variable is used to save the value
· Use event proxies as much as possible to avoid bulk binding events
· Use the ID selector as much as possible.
The ID selector is the fastest
· Touch Event Optimization .
Use Touchstart, Touchend instead of click, because fast impact speed. However, it should be noted that touch response is too fast and easy to cause misoperation
Fifth Step: Rendering optimization
HTML uses viewport.
Viewport can accelerate the rendering of the page, use the following code <meta name= "viewport" content= "Width=device-width, initial-scale=1″>
· reduce the DOM node .
DOM node too much affects the rendering of the page, should try to reduce the DOM node
· Animation optimization .
A) use CSS3 animation (b) as much as possible using requestanimationframe animations instead of SETTIMEOUTC) use CSS animations appropriately using canvas animations within 5 elements, 5 or more using canvas animations (iOS8 can use WebGL)
· High-frequency event optimization .
Touchmove, Scroll events can cause multiple render a) use Requestanimationframe to listen for frame changes to render at the correct time B) increase the time interval for response changes and reduce redraw times
· GPU acceleration.
The following properties in CSS (CSS3 transitions, CSS3 3D transforms, Opacity, Canvas, WebGL, Video) to trigger GPU rendering, please use (PS: The use of the transition will cause the phone to increase the power consumption)