1.HTML5 implements the script's Async property , this new attribute allows JS to load in a non-blocking mode in the browser, and the script has a defer attribute, This property is currently implemented by all browsers (except for Firefox and earlier versions of Chrome), IE is doing well and supports attributes from the outset.
Copy Code code as follows:
Async
<script Async src= "Dquery.js" async></script>
Defer
<script Async src= "Dquery.js" defer>
</script>
the difference between 2.async and defer:
Script with async or defer immediately downloads without blocking page parsing, and provides an optional onload event handler that is invoked after the script download completes to perform some initialization work related to this script. The difference is that async executes immediately (before the Window.onload event) as soon as the download is complete, and defer ensures that JS is executed in the order in which it was performed in the page (before the Domcontentloaded event).
3. To resolve browser compatibility issues, you can use the following code to process
Copy Code code as follows:
function Lazyload () {
var elem = document.createelement ("script");
Elem.type = "Text/javascript";
Elem.async = true;
ELEM.SRC = "js/dquery.js?v=11"; The corresponding JS file
Document.body.appendChild (Elem);
}
if (Window.addeventlistener) {
Window.addeventlistener ("Load", Lazyload, false);
else if (window.attachevent) {
Window.attachevent ("onload", lazyload);
} else {
Window.onload = Lazyload;}
Because it is asynchronous loading, the use of the corresponding JS content needs to be used in the Window.onload event, written directly in the page will report script errors, such as: