Overheads if i do multiple <script src?

Hi all, I’m wondering if there’s any overheads if i do 15 <script src=“…”></script>

does it reduce loading time significantly if i combine them into 1 single script?

Load time is increased more by the number of files than the size of the files. You will get better load time combining them.

Every script src=“…” generates an HTTP request. The number of HTTP requests can definitely create a slow down… especially depending on file size.

There are a number of things you can do to reduce these issues (compression, JS at bottom, etc).

Something to keep in mind, the same would apply for stylesheets.

Something I alluded to but didn’t really give the details I wanted. As long as your scripts can survive at the bottom of your file (before the closing body tag) then that’s where you’ll want to put them.

Each time the browser gets a JS src call it basically says “hang on a sec, I need to get this before I can proceed”. This can definitely cause a slowdown. Including your calls at the bottom of your files will allow rendering to start happening.

Combining the files is a great idea… slapping compression (i.e. YUI compressor) on that combined file is even better.

ok so if i’ve no intention of caching, wouldn’t it be faster if everything was within the <style></style> and <script></script> instead of importing ?

Speed depends on when the scripts are run and how they are loaded: http://stevesouders.com/efws/links.php?ex

hey thanks for the link.

ok so if i’ve no intention of caching, wouldn’t it be faster if everything was within the <style></style> and <script></script> instead of importing ?

Its a little faster if the code is on the page, but its not good practice for SEO and accessibility.

A few calls is no big deal. With 15 scripts I’d worry. If you can combine them into 2-4 scripts that would be better.