onload.js (678B)
1 /** 2 * Load the same url in many ways 3 */ 4 // 1) Notice in index.html the: 5 // <script src="same-url.sjs"></script> 6 7 // 2) Also the similar <script> tag in iframe.html 8 9 // 3) Via a Worker, in a distinct target 10 const worker = new Worker("same-url.sjs"); 11 worker.postMessage("foo"); 12 13 // 4) Via a named eval, in the same target 14 // Hold a global reference to this function to avoid it from being GC-ed. 15 this.evaled = eval("function sameUrlEval() {}; console.log('eval script'); //# sourceURL=same-url.sjs"); 16 17 // 5) Via a dynamically inserted <script>, in the same target 18 const script = document.createElement("script"); 19 script.src = "same-url.sjs"; 20 document.body.appendChild(script);