Optimization of web front-end performance is important
So what aspects do we need to start with for optimization? You can follow Yahoo’s front-end optimization
The content part
1. Minimize HTTP requests
Methods: 1. Reduce page elements (images, forms, Flash, etc.) 2. 3. Simplify the number of JS files and CSS files (combining scripts and CSS files can reduce HTTP requests). Some people like to break CSS into neat sections. Such as header. CSS, mianbody. CSS, footer. CSS such page maintenance and modification is improved, can speed up the server response time is a problem 4. Using location.href() instead of location.reload() location.reload() will refresh the page, Reload () the browser will read the local cache 5. Dynamic page static (users access dynamic pages to exchange data with the database server, dynamic page static, is the dynamic page to generate HTML files, with space for efficiency) void swap(int a, int b) { int temp = a; a = b; b = temp; Void swap(int a, int b) {a ^= b; void swap(int a, int b) {a ^= b; b ^= a; a ^= b; } This saves space by using the temporary variable temp, but takes longer to compute. Image Maps are also known as Image hotspots. Image Maps divide an Image into several regions, and each region points to a different URL address. These regions are also called hotspots, and Image Maps are only applicable to consecutive ICONSCopy the code
2. Reduce DNS lookup
Basic: Domain Name System (DNS) : translates Domain Name urls into server host IP addresses. Check whether the browser cache exists. If the browser cache does not exist, access the local DNS cache. If the browser cache does not exist, access the local DNS server. So DNS is also overhead, typically it takes the browser 20-120ms to find the IP address for a given URL, and the browser can't download anything from host until the DNS lookup is complete. TTL(Time To Live) : indicates the TTL of the DNS record returned from the search. If the TTL expires, the DNS record will be discarded. ****** Factors affecting DNS cache ****** 1. You can set the TTL value to indicate the DNS record time. The DNS cache will determine when DNS records are discarded based on the TTL value. Generally, it is not very large, mainly because of the problem of fast failover. The browser DNS cache also has its own expiration time, which is independent of the native DNS cache and relatively short, such as about 1 minute for Chrome. 3. The number of DNS records in the browser is also limited. If you visit a large number of websites with different domain names in a short period of time, the DNS records will be discarded and must be searched again. Even if the browser discards the DNS record, the operating system's DNS cache has a good chance of retaining the record, thus avoiding the delay associated with network queries.Copy the code
3. Avoid redirection
1. When defining the href attribute of the link address, use the most complete, direct address possible. Set the second parameter to false when using response. Redirect. 3. If migrating from test to production is involved, it is recommended to define the alias using the CNAME mechanism in DNS rather than forcing redirectsCopy the code
4. Make Ajax cacheable
Add the Expires header, cache-control headerCopy the code
5. Lazily loading components
react-lazy const CreateProject = lazy(() => { return new Promise(resolve => setTimeout(resolve, 2000)).then( () =>import('.. /common/CreateProject.js') ) })Copy the code
6. Preloaded components/lazy loaded components
Reduce the number of DOM elements
8. Separate components across domains
9. Use iframe sparingly
10. Put an end to 404
The Css part
12. Select <link> to discard @import 13. Avoid filters 14. Put style sheets at the topCopy the code
Js part
Eliminate duplicate scripts 16. Minimize DOM access 17. Use smart event handlers 18. Put the script at the bottomCopy the code
Javascript,Css
20. Compress JavaScript and CSSCopy the code
The picture
23. Don't zoom in and out of image 24 with HTML. Use small cacheable favicon.ico (P.S. favorites icon)Copy the code
Cookie
26. Place the component in a cookie-free fieldCopy the code
The mobile terminal
Make sure all components are smaller than 25K. 28. Pack the components into a composite documentCopy the code
The server
29.Gzip component 30. Avoid image SRC property being null 31. GET requests for Ajax 33. Clear buffers early 34. Use CDN (Content Distribution Network) 35. Add the Expires or cache-control HTTP headerCopy the code