SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    One Large JS file, lots of small, or embedded?

    Hi All,

    Im building a big project and have a questionthat i cant find a definitive answer for.

    Aside from programming cosmetics, and readability.
    Lets consider 200 functions, is performance affected by any of the above? Im after maximum performance rather than readbility.

    My first thought is that 200 functions in one file would cause a little slow down. But then maybe computers process that as if it were nothing and makes no difference?

    Thanks

  2. #2
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,266
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    I just read Felgall say in another thread that browsers will stop what they are doing while loading a JS script. Then again, calling 200 separate files means 200 separate handshakes with the server.

    If you mean, negotiation (some pages need some scripts and others don't), I have seen a dynamic loader as a solution to large scripts, where each page has a little script that calls what's needed for that page from the libs elsewhere... that way, the page who only needs 5 of the files only asks for 5, while the page than needs all 200 asks for those (caching should play a part here too).

    I'll see if I can find it. It might have been part of one of the JS libraries.

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool Thanks Stomme, that could be worth a look!

  4. #4
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,266
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    Hm, I'm not finding it already (but my google-fu is notoriously sucky), but now I wonder if the negotiation was done by the back-end? So that's possible.

    In general, you want cacheability, and so few as possible handshakes/calls to the server. So this suggests one giant file... however if only some pages are making use of the file I'd see about the dynamic adding of bits... just saw something about a trick built-into scriptaculous, so it wouldn't surprise me to see that most or all of the big popular libs had something similar.


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
  •