Does performance really matter? HTML 1. Avoid inline/embedded code: <html> <head> <meta charset="UTF-8"> <title>Browser Diet</title> <!-- CSS --> <link rel="stylesheet" href="style.css" media="all"> </head> <body> <a>hello</a> <!-- JS --> <script async src="script.js"></script> </body> </html> 1) The style is in the head, and the page renders quickly, which makes the user feel that the page loads quickly. On the contrary, you will first see a messy page layout, which gives people a bad feeling. When writing tag attributes, it is best to keep multiple identical tag attribute values in the same order. Can make gzip compression faster. CSS .img { background-image: url('image.png'); } After use: .img { background-image: url('data:image/png;base64,iVBORw0KGgo');} Base64 image encoding is only for individual images, not CSS sprite images, and supports mainstream browsers and IE8 and above. The number of http requests can be reduced, but for HTML and CSS without gzip compression, it is not advisable to reduce the large files obtained by http requests. In summary, continuous jpg format is better for performance. var vst = document.createElement('script'); vst.type = 'text/javascript'; vst.async = true; vst.src = srcIndex; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(vst, s); When some third-party files become a problem to download or cause heavy page loading. We need to load these files asynchronously, async is a good way. var str = "nanananana"; for (var n = 0; n < str.length; n++) {} After use: var str = "nanananana", strLgth = str.length; for (var n = 0; n < strLgth ; n++) {} Loops consume a lot of performance. Storing the looped objects can reduce the need to perform object calculations in each loop. var coored = document.getElementById("ctgHotelTab"); document.getElementById("ctgHotelTab").style.top = coored.offsetTop + 35 + "px"; After use: var coored = document.getElementById("ctgHotelTab"), offsetTop = coored.offsetTop + 35; document.getElementById("ctgHotelTab").style.top = offetTop + "px"; When the layout of an element remains unchanged but the appearance changes, it causes a repaint. |
<<: vmware virtual machine ubuntu18.04 installation tutorial
>>: Implementation of CSS Fantastic Border Animation Effect
Download tutorial of mysql-connector-java.jar pac...
Html event list General Events: onClick HTML: Mous...
The difference between http and https is For some...
This article example shares the specific code of ...
Install the required environment 1. gcc installat...
1 Problem Description This article sorts the esta...
Problem description (environment: windows7, MySql...
Table of contents Docker version Install Docker E...
This article shares the specific code of Vue usin...
Implementation ideas: Use text-shadow in CSS to a...
GitHub address, you can star it if you like it Pl...
Mini Program Data Cache Related Knowledge Data ca...
First, download a series of things from the Alipa...
Route parameters, route navigation guards: retain...
<br />For an article on a content page, if t...