SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    $books++ == true matsko's Avatar
    Join Date
    Sep 2004
    Location
    Toronto
    Posts
    795
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using the defer attribute

    Does anyone know exactly what the defer attribute for the script tag is? I read that it tells the browser to load the page first (once the body tag is fully loaded) and then load the contained <script>.

    If so then how does it cope with cached scripts? Say for example a <script> has already been loaded then the page is accessed again, will the <script> contents be executed right away since the contents do not have to be downloaded?

    Also, if you do not have a src attribute (the contents are on the page and not in a separate file) then does the defer attribute really do anything?

    I am aware that it's in the HTML specification and that it's not a MSonly thing. But this is the first time I've ever seen the defer attribute, so I don't think it's really mainstream. All of my scripts that load up when the page is loaded are triggered by window.onload and since lately I use mootools, then they are loaded after window.onDomReady.

    I tried using the defer attribute with mozilla and it didn't seem to work.

    How exactly does this feature work?

    ------- EDIT -------

    Correction This feature seems to be MSonly even though it's in the HTML specification. This feature isn't really very useful for any other browsers.
    I can't believe I ate the whole thing

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    To the best of my knowledge it tells Internet Explorer that the content of the script isn't needed until after the page finishes loading and so the browser can give priority to downloading other files first. I don't think it has any effect on other browsers as they haven't implemented it yet.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I think you might find this interesting: http://dean.edwards.name/weblog/2006/06/again/

  4. #4
    $books++ == true matsko's Avatar
    Join Date
    Sep 2004
    Location
    Toronto
    Posts
    795
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raffles View Post
    I think you might find this interesting: http://dean.edwards.name/weblog/2006/06/again/
    Very Nice! Now I understand how the onDomReady handler for mootools works Many Thanks
    I can't believe I ate the whole thing

  5. #5
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It would be wonderful if all browsers could take the Mozilla and Opera lead and implement DOMContentLoaded. Then this rather hacky approach (the IE and Safari methods are somewhat nasty) wouldn't be necessary.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •