View Full Version : Can I combine Javascripts?

12-24-2011, 10:08 AM
I have 4 or 5 Javascripts on my home page at drachsi.com These slow the page down. Can I combine them into 1 Javascript, and would it make the page load faster?

Season's Greetings to all


12-24-2011, 05:54 PM
You might be able to combine some of them but it wouldn't speed the loading of the page much if at all.

You might want to look into:

gzip server compression

Google it. With it or similar methods files are sent in compressed form to the browser which unpacks them on the fly. In cases like yours this can speed up the loading of the page, especially for slower connections.

I also noticed though that there seemed to be a lot of iframes on the page. Some or all of these might be generated by scripts. If these can be reduced, the page will load faster.

In any case, it's pretty fast already. Certainly not the fastest. But at 100mbps (my top speed, probably less in any given case), it's well under the dreaded 8 second limit. Took about 3 seconds, if that in IE 9 and in Firefox 8.

12-25-2011, 12:09 AM
Combining them won't make them have any less text, so they won't load any faster (downloading speed). However, it would make your page have fewer requests (files requested from the server) so that could significantly speed things up.

Generally speaking, you can just cut and paste all of your Javascript into a single file. However, there are three things to consider:
1) Save a backup as-is in case something goes wrong.
2) Only do this if everything is working perfectly right now. Test separately for convenience.
3) Be absolutely positive that everything in the single file is in the same order as in the page. If so, it should be fine. But order does matter sometimes. Also, you can't combine them in this way if the script appear in different places in your page (eg, some in the <head> section and others mixed in the <body> section). You can combine any that appear next to each other in the source code as-is.

You can also look into minify, from google. It takes your script and removes extra stuff. They become completely unreabable and difficult to edit, so always keep a backup (then edit and re-minify if you need to change anything), but they will load faster.