Results 1 to 3 of 3

Thread: Can I combine Javascripts?

  1. #1
    Join Date
    Jul 2008
    Posts
    24
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Thumbs up Can I combine Javascripts?

    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

    Drachsi
    Last edited by jscheuer1; 12-24-2011 at 05:37 PM. Reason: Format

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •