DOMContentLoaded shim - domready.js #27
Comments
Diego has told me that he has an update for that script. |
I'll throw my variation into the circle and see if anyone bites... https://github.com/Integralist/DOMready ...it has had feedback from both @jdalton and @dperini to help catch out quite a few different scenarios so I think it's pretty robust |
If the JavaScript for your site is relatively simple, you could just stick your JavaScript at the bottom of the page, and run it "inline" in the script file. I've done this on a few sites I've made. Avoids the need for a DOMReady function in a lot of situations :P |
@Daniel15 Depending on your script, that may trigger “Operation Aborted” errors in old IE: http://mths.be/ieoa In those situations you still need a DOMContentLoaded shim. |
@mathiasbynens How likely is that to happen, though? I've never encountered that myself. |
@Daniel15 It happens when you use |
Ps, thanks @Daniel15 for the pull request. Replacing the IIFE with a boolean coercion not only is cleaner syntax but better perfoming: Integralist/DOMready#1 |
@mathiasbynens Huh, that is interesting. I've used |
I came across the "Operation Aborted" issue today. It only appears to happen when you try to modify a HTML element that's not the script tag's immediate parent. So, this could trigger it: <body>
...
<div>
<script>
document.body.appendChild(...) // :(
</script>
</div>
</body>
</script> But this should work fine: <body>
...
<script>
document.body.appendChild(...) // This works :)
</script>
</body>
</script> This is mentioned in a post on the IEBlog which confirms it somewhat:
So as long as your script is directly above the </body>, it should work properly. |
closing as https://github.com/dperini/ContentLoaded is it. thx @rpflorence for the suggestion (1 yr ago :) |
Word. |
Basically we need a micro-library for DOMContentLoaded-like event binding that works everywhere.
And it should be as small as possible.
And not suck.
One that we can trust.
The text was updated successfully, but these errors were encountered: