1, the browser encountered JS code will pause the page download and rendering, who know the JS code will not give the HTML to rape (change);
2. Delay Script loading: Defer property
<HTML><Head> <title>Script Defer Example</title></Head><Body> <Scripttype= "Text/javascript"defer>Alert ("defer"); </Script> <Scripttype= "Text/javascript">Alert ("Script"); </Script> <Scripttype= "Text/javascript">window.onload= function() {alert ("Load"); }; </Script></Body></HTML>
Browsers that do not support defer properties have the following popup order: "Defer", "script", "load". deferon browsers that support properties, the order of popup is "script", "defer", and "load". Note that the defer element with the attribute is not followed by the <script> second, but onload is called before the event is triggered.
3, dynamic loading many JavaScript files, the browser does not guarantee the order of file loading. Load multiple JavaScript scripts with the Loadscript () function to ensure that the loading order
function () { loadscript() (function () { loadscript () { alert ( "All Files is loaded!" ); }); });});
4. There are several ways to reduce the impact of JavaScript on performance:
- Placing all the labels at the bottom of the
<script> page, that is </body> , before closing the tag, ensures that the page has been rendered before the script executes.
- Merge the scripts as much as you can. The fewer labels in the page
<script> , the faster the load and the quicker the response. This is true for both the outer-chain script and the inline script.
- A way to download JavaScript scripts without blocking:
- Use
<script> the defer attribute of the label (only for IE and Firefox version 3.5 or above);
- Use dynamically created
<script> elements to download and execute code;
- Use the XHR object to download the JavaScript code and inject it into the page.
Detailed Link: https://www.ibm.com/developerworks/cn/web/1308_caiys_jsload/
Performance optimizations for "Digest" JavaScript: Loading and executing