Error loading javascript

First question:

About Dynamic Script Elements

var script  = document.createElement ("script");
script.type = "text/javascript";
script.src  = "script.js"; document.getElementsByTagName_r("head")[0].appendChild(script);

The important thing in this method is that the file is downloaded and executed without blocking other page processes, regardless of where the download starts. You can even put this code in the <head> of the document without affecting the rest of the page.

I want to know what is the difference between dynamic Script elements and these codes

<script type="text/javascript" src="script.js"></script>

Why do Dynamic Script Elements load and execute a file without blocking other page processes and will there be another?

Second question:

I know that page loading and rendering should stop and wait for the Script to complete before continuing, so I put the scripts at the bottom to </body>

XMLHttpRequest Script Injection , lazyload, , ?

- ?

+4
2

, Script

Script. HTML- .

Script , HTML- , , . Script , .. HTML- Script , , Script HTML , .

Dynamic Script , ?

, . , /HTML , . Script , . Script, HTML- , . (, document.write() , , , ( ), . defer async Script, HTML- . , , .

XMLHttpRequest Script Injection , lazyload, ?

, Script. Script , Script ( ). , . , , , , .

, defer async Script, . :

+2

script - . document.write(), Dom, , script . , , Dom .

Script , .

lazyload libs / . , .

0

Source: https://habr.com/ru/post/1538251/


All Articles