Setting a script element's `src` attribute after insertion does not load the `src` target.
See original GitHub issueIf you modify a script’s src
attribute after the element has been attached, the target script is never loaded.
This example will always log false
to the console:
script.js
window.script_executed = true;
runner.js
const jsdom = require('jsdom');
const window = jsdom.jsdom("").defaultView;
window.script_executed = false;
const script = window.document.createElement("script");
window.document.body.appendChild(script);
script.src = "script.js";
// assume script.js will load asynchronously
setInterval(() => {
console.log(window.script_executed);
}, 1000);
A comparable script that executes in a browser and logs true
:
<html>
<body>
<script type="text/javascript">
window.script_executed = false;
var script = window.document.createElement("script");
window.document.body.appendChild(script);
script.src = "script.js";
setInterval(function() {
console.log(window.script_executed);
}, 1000);
</script>
</body>
</html>
Issue Analytics
- State:
- Created 7 years ago
- Comments:17 (13 by maintainers)
Top Results From Across the Web
Programmatically change the src of an img tag - Stack Overflow
at first I have a default src which is "../template/edit.png" and I wanted to change it with "../template/save.png" onclick. UPDATED: here's my ...
Read more >HTMLScriptElement - Web APIs | MDN
A string representing the URL of an external script. It reflects the src attribute. HTMLScriptElement.event Deprecated. A string; an obsolete ...
Read more >The ultimate guide to iframes - LogRocket Blog
Not a fan of iframes? This post provides an overview of the tag's best features, shows you how to use them, and how...
Read more >.insertAfter() | jQuery API Documentation
Description: Insert every element in the set of matched elements after the target. version added: 1.0.insertAfter( target ). target. Type: Selector or ...
Read more >Insert and edit images in Dreamweaver - Adobe Support
When you insert an image into a Dreamweaver document, a reference to the image file is generated in the HTML source code. To...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t think further testing is helpful here. It’s clear that there are implementation bugs in resource loading with regard to attributes changing. I’ll spend some time fixing them.
The iframe behavior is actually per-spec and matches browsers, but I have fixes for link and script in master now. They will be going out in the next release.