[Javascript] Speed of loading JS files

Scott Reynen scott at randomchaos.com
Fri Jun 20 17:26:56 CDT 2008


On [Jun 20], at [ Jun 20] 3:58 , Skip Evans wrote:

> Hey all,
>
> Our system that uses lots of AJAX in a total of
> 154K. However, the site is taking a long time to
> load the initial page and the individual JS files,
> approximately 10 to 15 seconds of waiting.
>
> The JS is in about 39 separate files simply
> because we build individual PHP and JS files per
> system module and that's just how it worked out
> for this application.
>
> Does the number of files greatly affect that
> initial download off all the JS?

Sometimes, yes.  Every individual file has added overhead with the  
HTTP headers for the request and response.

> Would it speed up
> significantly if we combined them into just a
> couple of files?

That depends on how you define "significantly."  It will certainly  
speed it up somewhat.  By your numbers, each file is about 4k.  If we  
assume (conservatively, I think) the HTTP headers average only 0.4k,  
that's already 10% of your transfer, not including the time it takes  
the browser to make and monitor the requests.

> If not, could someone suggest a more efficient way
> to get the JS code to the browser?

Assuming the JS files aren't changing often, make sure you're sending  
headers to cache these files so they're only loaded once.  This is  
especially important if you have a lot of repeat traffic.

YSlow can give you more detail on, as the name implies, why a site is  
slow:

http://developer.yahoo.com/yslow/

Peace,
Scott




More information about the Javascript mailing list