Closed rvagg closed 11 years ago
It occurred to me that since bonzo.create
temporarily adds elements to the dom in order to create them, the scripts would download and execute regardless of whether the user is ready for them to or not... Even if we get this working, scripts should still only execute if they're appended to the DOM, IMO.
Or wait... maybe not, since it doesn't get added to the document
's head
or body
objects themselves. My bad, I think... :frowning:
If you're suggesting that they're temporarily added to a DOMFragment, then it's fine and safe.
But if you're suggesting they're added to the real DOM, it doesn't matter where a script element is added, the behavior is the same. When it's added, it's made subject to execution. In all versions of IE, the browser will start fetching the script as soon as you set src
property, but it will still not execute it until after you've added it to the DOM.
However, some people actually utilize the behavior that IE prefetches scripts into the cache like that, so that's not necessarily a feature to code around or avoid. But certainly you don't want scripts to execute too early because you've inserted them into the real DOM "temporarily".
@getify yeah, I later realized that that was indeed what I was suggesting, so there's no problems... (Although, in any case, the bug isn't resolved yet, so it would still be at least temporarily moot.)
As far as IE goes, do you happen to know if it also prefetches scripts with type
s set to bogus, non-text/javascript
values?
IE <= 9 (dunno about 10, honestly) and older webkit (aka, webkit pre Mar 2011) fetch those types of scripts. The spec now specifically forbids such fetching, so any new and spec-conforming browser will not.
[Sorry, I think I misread what you wrote above and you actually answered that.]
Also, I wonder why the spec would forbid that... seems useful to me. Do you have any mailing list links or anything about the topic? I'm interested to know more, but hate to keep cluttering the bonzo tracker.
Thanks, BTW.
nevertheless, the way to fix this is to detect that a script tag has in fact been included, and create one from scratch. perhaps i'll give this one a go...
i've added a minimum viable solution for folks that require this functionality. it works as such for now
bonzo(bonzo.create('<script src="hello.js">')).appendTo(document.body)
note that it should not execute until it's appended to the live DOM. ultimately it work when the normalize stuff is in... (or with Ender now)
bonzo('<script src="hello.js">').appendTo(document.body)
Woah, cool!
Trail starts here: https://twitter.com/getify/status/248137610113986560
I gather that while we can create script elements they don't actually work.
/cc @getify