question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting a script element's `src` attribute after insertion does not load the `src` target.

See original GitHub issue

If 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:closed
  • Created 7 years ago
  • Comments:17 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
domeniccommented, May 22, 2016

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.

0reactions
domeniccommented, Jul 2, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found