Load and run the extension script & lt; scripttype
Loading and running
Extension script
The script js file is downloaded only when the dom is loaded.
Dynamic script Element
Var script = document. createElement ("script"); script. type = "text/javascript"; script. src = "file1.js"; document. getElementsByTagName_r ("head") [0]. appendChild (script) does not block the processing process of other pages no matter where the download starts.
XHR Script Injection
Var xhr = newXMLHttpRequest (); xhr. open ("get", "file1.js", true); xhr. onreadystatechange = function () {if (xhr. readyState = 4) {if (xhr. status >=200 & xhr. status <300 | xhr. status = 304) {var script = document. createElement ("script"); script. type = "text/javascript"; script. text = xhr. responseText; document. body. appendChild (script) ;}}; xhr. send (null) generates inline js Code on the html page. It is not executed immediately after being downloaded, so it can control its execution status.
Recommended Practices