A few years ago Dean Edwards brought us this workaround to the document.onload problem. The IE version of the solution involved appending this snippet to the document:
<script defer src=ie_onload.js><\/script>;
Dean was also pretty adamant on the fact that this was the closest solution to perfection he could find and dismissed any solution that involved the onreadystatechange attribute as being unreliable (see comments).
Subsequent refinements on his solution still involved some version of <script defer> and most JS framework implemented it, including jQuery.
Today, I'm perusing JQuery 1.4.1's source and I can't find it.
At which point was it dropped and why?
Deferred() method in JQuery is a function which returns the utility object with methods which can register multiple callbacks to queues. It calls the callback queues, and relay the success or failure state of any synchronous or asynchronous function.
You should use defer for all other scripts. defer is great because it: Gets loaded as soon as possible — so it reduces load times. Doesn't execute until everything you need is ready — so all the DOM you need is there.
In practice, defer is used for scripts that need the whole DOM and/or their relative execution order is important. And async is used for independent scripts, like counters or ads. And their relative execution order does not matter.
The defer attribute is a boolean attribute. If the defer attribute is set, it specifies that the script is downloaded in parallel to parsing the page, and executed after the page has finished parsing. Note: The defer attribute is only for external scripts (should only be used if the src attribute is present).
It was removed in the jQuery 1.2.2 release, you can find the release notes here.
Internet Explorer document ready drastically improved. We use a new technique inspired by Diego Perini. It allows us to not have to do a
document.write()
anymore, which is really fantastic.
Here's the 1.2.1 Version vs the 1.2.2 version.
The main motivation was to remove the document.write
and avoid the problem of IE still triggering the ready
a bit too early, so now it's completely rewritten to listen to onreadystatechange
(in IE) and fall-back to window.onload
if all else fails.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With