SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to address download issues with large JS files

    I have one page on my site that contains a huge javascript file (500kb). I'm compressing it to help out, but it still takes about 13 seconds for the page to load. I'm looking for a way to make this workable for a visitor.

    Is there a way to load javascript files after the body of the page so that the rest of the page displays quickly and then I can put up some kind of message that says "downloading..." or something like that? Right now I am including the file in the head and it waits until everything is downloaded before the page displays. How do other address this?

    I'd like something similar to what they use on Pandora.com.

    Thanks!

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you can use the DEFER attribute of the script tag to do this.

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I'll check it out. Is there an event that gets generated when the deferred scripts finishes loading in the browser? Or maybe an event when everything on the page has been downloaded?

    Right now I'm calling my javascript functions from the body onload event, and if I've deferred the JS file downloads, I'd want to call the javascript files only once the JS files have finished downloading.

  4. #4
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I break it up.

    I load a small script file that waits for an onload event and
    then adds any javascript the page can use.

    Its surprising how little code you need for the first few seconds on a new webpage. And of course the file will come from the cache after the first visit.


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
  •