1. Causes:
Each time you encounter a <script> tag, the page must stop waiting for the code to download and finish, before proceeding with the rest of the process.
2. Reduce the impact of JavaScript on performance
1. Put all JavaScript files before </body>, which ensures that the page has been rendered before the script executes.
2. Merge scripts. The fewer <script> tags on the page, the faster the load and the quicker the response. Whether the outer chain script or the inline script.
3. There are a variety of non-blocking download JavaScript methods:
1. Using the Defer property of <script>, Async property (IE)
2. Use dynamically created <script> elements to download and execute code
function Loadscript (URL, callback) {varScript = Document.createelement ('Script'); Script.type="Text/javascript"; if(script.readystate) {//IE9 belowScript.onreadystatechange =function () {if(script.readystate==' Complete'|| script.readystate=='Loaded') {callback (); } } }Else{script.onload=function () {//Firefox chrome Safair operacallback (); }} script.src=URL; Document.head.appendChild (script);}
3. Download the JavaScript code using the XHR object and inject it into the page
Load and execute-high performance JavaScript