Printable Version of Topic

Click here to view this topic in its original format

Forums _ Webmasters' Corner _ Javascript

Posted by: spambot Feb 15 2011, 01:26 AM

Is it better to have one big JS file or to link to them separately?

Posted by: serotonin Feb 15 2011, 02:08 AM

yea

Posted by: spambot Feb 15 2011, 02:15 AM

you so helpful

Posted by: boot Feb 15 2011, 02:38 PM

I don't think it really matters on small-scale sites but I usually link them separately anyway.

Posted by: Maccabee Feb 15 2011, 05:09 PM

One big file. Fewer http requests but the difference is so small it's not worth it because you lose the organization. Also look at this this:

http://rakaz.nl/2006/12/make-your-pages-load-faster-by-combining-and-compressing-javascript-and-css-files.html

You'd have to weight the pros and cons though because it reduces size therefore making it load faster but it also add pressure on the server which may end up making it slower. (It probably won't unless you have a really crappy server with a heavy load already.)

Lastly, read this. Every web design should read through it.

http://developer.yahoo.com/performance/rules.html

Posted by: spambot Feb 15 2011, 05:54 PM

I have something like 9 js files...which I am assuming is a lot. Size and speed is becoming a concern for me. I am just kinda learning this shit as I go.

Thanks for the links

Posted by: boot Feb 16 2011, 02:58 PM

QUOTE(Maccabee @ Feb 15 2011, 04:09 PM) *
One big file. Fewer http requests but the difference is so small it's not worth it because you lose the organization. Also look at this this:

http://rakaz.nl/2006/12/make-your-pages-load-faster-by-combining-and-compressing-javascript-and-css-files.html

You'd have to weight the pros and cons though because it reduces size therefore making it load faster but it also add pressure on the server which may end up making it slower. (It probably won't unless you have a really crappy server with a heavy load already.)

Lastly, read this. Every web design should read through it.

http://developer.yahoo.com/performance/rules.html

the way I figure I figure one big file is better for smaller sites but if you've got a lot of things going on but only need a few things on the home page, one or two more on the buy page, only one thing on a comments page, etc. then it's better to go with several smaller js files. say someone wants to browse your site for something but never goes to the checkout or comments sections it doesn't make sense to send them all that code anyway.

since js files are cached anyway, it's not like the handful who actually use everything will be making all that many http requests from 10 or 12 extra files

Posted by: mipadi Feb 16 2011, 04:38 PM

Unless your site is getting something on the order of 10,000+ hits/day, it doesn't really matter.

But if you're asking purely for intellectual masturbation:

If you have one big file, your web browser will make 1 request -- but it'll have to wait for the entire file to download.
If you have a bunch of small files, your web browser can request them in parallel (to a limit -- a browser will only open a limited number of connections to a given web server).
Either way, the JavaScript files may be parsed one at a time anyway.

If you do have a really high-traffic site, you'll gain a bigger performance boost by gzip-compressing your JavaScript (and CSS) files. Also, if you're using jQuery, use Google's loader or URL to request the jQuery script, since your visitor's browser will likely already have it cached.

Posted by: Maccabee Feb 17 2011, 12:30 AM

Check out Yslow for firebug.

Posted by: spambot Feb 17 2011, 12:43 AM

QUOTE(mipadi @ Feb 16 2011, 03:38 PM) *
Unless your site is getting something on the order of 10,000+ hits/day, it doesn't really matter.

But if you're asking purely for intellectual masturbation:

If you have one big file, your web browser will make 1 request -- but it'll have to wait for the entire file to download.
If you have a bunch of small files, your web browser can request them in parallel (to a limit -- a browser will only open a limited number of connections to a given web server).
Either way, the JavaScript files may be parsed one at a time anyway.

If you do have a really high-traffic site, you'll gain a bigger performance boost by gzip-compressing your JavaScript (and CSS) files. Also, if you're using jQuery, use Google's loader or URL to request the jQuery script, since your visitor's browser will likely already have it cached.


Yeah, I was mostly asking for future reference and had general curiosity and couldn't find really a straight answer on google. Thank you kind sir.

What I am working on now is just a 1 page portfolio so I had a feeling it wouldn't matter.

Posted by: mipadi Feb 21 2011, 07:32 PM

QUOTE(spambot @ Feb 17 2011, 12:43 AM) *
Yeah, I was mostly asking for future reference and had general curiosity and couldn't find really a straight answer on google. Thank you kind sir.


Sure.

For reference, the site I manage gets about 40,000 hits/day. That's not an extremely high volume of traffic, but the visits are very "bursty" -- sometimes we get a couple thousand hits per hour for a few hours. We have many JS and CSS files, and we just use gzip compression; on the HTML side, we use memcached to aggressively cache HTML templates and minimize database calls. It works fairly well -- we run the entire site off of a dual-core server instance.