MCPcopy
hub / github.com/ampproject/amphtml / loadScriptNew

Function loadScriptNew

ads/vendors/momagic.js:41–62  ·  view source on GitHub ↗

* Load the script asynchronously * @param {string} url * @param {!Function} callback

(url, callback)

Source from the content-addressed store, hash-verified

39 * @param {!Function} callback
40 */
41function loadScriptNew(url, callback) {
42 const script = document.createElement('script');
43 script.type = 'text/javascript';
44 if (script.readyState) {
45 // only required for IE <9
46 script.onreadystatechange = function () {
47 if (script.readyState === 'loaded' || script.readyState === 'complete') {
48 script.onreadystatechange = null;
49 callback();
50 }
51 };
52 } else {
53 //Others
54 script.onload = function () {
55 callback();
56 };
57 }
58 script.id = 'interactive_js_ampcode';
59 script.defer = true;
60 script.src = url;
61 document.getElementsByTagName('head')[0].appendChild(script);
62}

Callers 1

momagicFunction · 0.85

Calls 1

callbackFunction · 0.70

Tested by

no test coverage detected