Recently with colleagues to do a sharing meeting, the theme is mobile front-end performance optimization, mainly share some of the methods to provide mobile page loading speed. Share the theme is colleagues want to explain the content is also provided by colleagues, I am responsible for, for me, 2 of the difficulty is the same, let me find the content of sharing, I feel that their ink is very few, what can be shared to everyone, let me say, I dare small, easy tension, but whether it is the turn to bear, In retrospect, still a little disturbed, always envy those steady, full of self-confidence, speech to the people, I am sorry, I am not this kind of person, I hope next time I can improve point.
For example, the 4 stages of page loading can be optimized accordingly.
I talked about preloading, loading on demand, using CSS3 animations, compressing pictures and event proxies, personally think, compressed pictures using Tinypng is really convenient, and the clarity of the picture almost nothing change, the event agent is a good thing, so far I have not used, next, will slowly try to use. The advantages and disadvantages of each method are as follows:
| Method |
Advantages |
Disadvantages |
| Pre-load |
Experience fluency after loading |
Increase user wait time, easy to cause user churn |
| Load on Demand |
Speed up the first screen display and reduce overall traffic |
Relatively large development costs, which can lead to a lot of repainting, poor performance |
| Animation acceleration |
Experience Fluency |
Large Memory overhead |
| Image compression |
Reduce overall traffic |
Reduced image quality |
| Event Proxy |
Improve performance, reduce the risk of crashes,
No need to rebind events after DOM update |
Events are triggered in the bubbling phase and are not suitable for certain requirements |
Here's an example that takes advantage of the event proxy and swipe:
vartouchobj={}; Window.addeventlistener ("Touchstart",function(e) {Touchobj.istap=true; Touchobj.isswipe=false; TOUCHOBJ.SX=e.touches[0].pagex; Touchobj.sy=e.touches[0].pagey; }) Window.addeventlistener ("Touchmove",function(e) {Touchobj.istap=false; Touchobj.nx=e.touches[0].pagex; Touchobj.ny=e.touches[0].pagey; vardeltay=touchobj.ny-Touchobj.sy; if(deltay>0){ //Swipe down //Do somethingTouchobj.isswipe=true; E.preventdefault (); } Else if(deltay<0){ //Swipe up //Do somethingTouchobj.isswipe=true; E.preventdefault (); }}) Window.addeventlistener ("Touchend",function(e) {if(!touchobj.istap | | touchobj.isswipe)return; varthat=E.target; Switch(that.id) { CaseA: //Do something Break; Case"B": //Do something Break; default: if(That.classList.contains ("SomeClass")){ //Do something } } })
Mobile front-end performance optimization