Compressing and Deploying JavaScript

For AJAX, deploying JavaScript files may be important for you or not. If you are professional in AJAX, you must know the details of JavaScript deployment.

First, you can compress your JavaScript files before deploying them. Common compressors may cut 50% off of file size for normal JavaScript. That is to say, if your packed *.js is about 100k, the compressed *.js may be 50k. The compressed *.js may take about 100ms to decompress, but it when comparing to 50k over 1Mb/s bandwidth ( 50k * 8 / 1M = 0.4 s = 400ms). It worths such compressing. Usually bandwidth is not quite good as 1Mb/s, it will much better for compressed JavaScript.

Some well-known JavaScript compressors are Dean Edwards’ Packer and Shrink Safe by Alex at Dojo. You may find some other compressors, like Java2Script’s LZ77 JavaScript Compressor.

Second, you can send out your JavaScript files as gzip-encoded by Apache server. For most of modern browsers, gzip-encoding can be accepted. So you should configure your Apache server to do so especially when your JavaScript is over 200k. In common cases, gzip-encoding saves over 75% of JavaScript bandwidth. That is to say, 200k JavaScript only takes up 50k transmission. What a great improvement.

But please pay attention to some defects of JavaScript gzip-encoding for some browsers, like IE. Well, Internet Explorer takes up 80%+ of browser shares. You must not ignore IE’s defects on dealing JavaScript gzip-encoding. As IE6.0 SP2 and IE7+ already fixed this bug. You should support these two browsers, as it may get more and more market share.

So when configure .htaccess file for Apache httpd server, you should ignore those buggy IE browser or non-supported browsers. Here is my .htaccess file:

<IfModule mod_deflate.c>
# Netscape 4.x or IE 5.5/6.0
BrowserMatch ^Mozilla/4 no-gzip
# IE 5.5 and IE 6.0 have bugs! Ignore them until IE 7.0+
BrowserMatch \bMSIE\s7 !no-gzip
# IE 6.0 after SP2 has no gzip bugs!
BrowserMatch \bMSIE.*SV !no-gzip
# Sometimes Opera pretends to be IE with "Mozila/4.0"
BrowserMatch \bOpera !no-gzip
AddOutputFilterByType DEFLATE text/css text/javascript application/x-javascript
Header append Vary User-Agent
</IfModule>

For more information about this gzip-encoding configuration, please google “IE gzip javascript encoding” or read Joshua Eichorn’s blog article “Compressing JavaScript and CSS”.

Third, this is still about gzip-encoding. But this method tries to include JavaScript in HTML sources directly. As IE has no bugs on decoding gzip-encoded HTML files, compress JavaScript in this way will suite for most IE6 users. As far as I know, GWT uses this way to send out their JavaScript. But loading those HTML files in an embed IFRAME may make the whole architecture a little strange or hard to understand. Few people uses this method.

Maybe there are some other ways to compress and deploy JavaScript. Please let me know or discuss with me if you have a new one.

This entry was posted in Architecture, Hacks, JavaScript. Bookmark the permalink.

24 Responses to Compressing and Deploying JavaScript

  1. Pingback: Java2Script Pacemaker » Blog Archive » Compressed JavaScript on Apache HTTPD Server

  2. to go travel says:

    I do enjoy the manner in which you have framed this problem plus it really does supply me some fodder for consideration. Nevertheless, from everything that I have observed, I only hope when the remarks stack on that individuals remain on issue and in no way start on a tirade involving the news of the day. Still, thank you for this superb piece and although I can not go along with this in totality, I respect the point of view.

  3. Considerably, the actual publish is typically the finest about this deserving topic. I agree with your outcomes and in addition could excitedly anticipate your potential updates. Basically just stating thank you are going to not merely you should be sufficient, for that amazing quality inside your writing. I’ll right away seize your rss feed to stay up-to-date with any kind of updates. Genuine perform and in addition much achievement inside your enterprise dealings!

  4. you’re in point of fact a very good webmaster. The site loading velocity is incredible. It seems that you are doing any distinctive trick. In addition, The contents are masterpiece. you’ve done a fantastic activity on this topic!

  5. web Site says:

    Why visitors still use to read news papers when in this technological globe the whole thing is
    existing on web?

    Stop by my web-site – web Site

  6. Find virtually any potential problems consequently there is no leaking or disorder.
    Therefore, I posed Ken Minn, CEO and Founder this question: ‘Will having
    my phone by an air vent, in my car affect its performance
    or damage the phone in any way shape or form’.

    The aircon and heating system is one of the most neglected
    parts of a residential home.

  7. It’s not as though your site is buried on page 35 or that you win no traffic at all that’s
    the problem. You are not in control of the success of the terms.

    And yet, we as a society are becoming increasingly reliable on the internet; using
    it for everything from work, to satisfying our shopping needs and even down to planning that perfect holiday.

    Search engine optimization services can provide you with just the right
    strategies and methods to improve your page ranking and direct a good amount of traffic to
    your site. One of the biggest stumbling blocks with working
    out how SEO works is that – apart from an inner circle
    at companies like Google – no-one knows the precise mix of how search results are arrived at.

  8. Commercial emails have benefits both for the consumers and the business.
    Aside this, email marketing is using the general
    socal networking devices like Facebook, Twitter
    etc. Your marketing strategy should be able to covert
    yor visitors nto customers. o It is a good practice to respect recipients’ privacy.
    There are various ays and tips to approach thee potential subset
    of customers.

    Here iis my homepage :: bulk email service

  9. In the end, you are going to be thanking yourself for it, considering that working out with
    fitness center machines is far additional effective, in terms of obtaining and staying in shape.

    my homepage weereneten.receptenvooriedereen.nl

  10. Monte says:

    Though they had been used as early because
    the 1850s on rifles, and even earlier for different tasks, till the
    eighties, when optical system and assault rifle combinations such as the Austrian Steyr AUG and
    the British SUSAT mounted on the SA80 , became normal challenge, army use of telescopic sights was restricted
    to snipers due to the fragility and expense of optical components.

  11. Dolores says:

    I believe stock technicians who make recommendations solely on charts are
    stuffed with it. Here is an instance and why it’s good to take inventory charts
    with a grain of salt before you buy into using them with out any
    other type of analysis.

  12. Berenice says:

    We know loads of non-girls who’d get a kick out of an iPhone pictures equipment , a leather-based passport cover — hell, even this
    eyeball massager However for each bra set, pair of delicate earrings, and mascara we’ve
    put into a present guide, this slideshow ought to offer
    you concepts for these in your procuring listing who prefer things on the opposite finish of the spectrum.

  13. domain says:

    Good site you have here.. It’s hard to find high-quality writing like yours these
    days. I seriously appreciate people like you! Take care!!

  14. CSGO says:

    Thanks for offering these kinds of superb posting

  15. Death is a veil which those who live call life, Sleep and it is lifted.

  16. Before the mods kick me out, can I post my rod for sale here, or is there a better place on here? I have to have surgery and will miss a bit of I’m trying to survive financially while I’m Thanks

  17. I just want to thank you for providing these awesome tips on compressing and deploying javascript. I’ve learned something good here. Thank you

  18. Elvia says:

    Make your plans now to hjtch us annd tons of of fundraising and primenet direct marketing solutions llc (Elvia) professionals on the Washington Nonprofit
    Conference, a two-day event where you’ll trade revolutionary advertising aand marketing and
    fundraising ideas, generate insightful solutions and assume creatively thgat can assist yyou make the relationship along with
    your donors even stronger.

  19. Andy says:

    Postcards – While most people have stepped away from direct addvertising aas a result of electronic mail advertising is so inexpensive, If yoou want to
    stand out, think about junk mail!

    my weblog free marketing ideas for insurance agents (Andy)

  20. twitter.com says:

    Online advertising and marketing agency jobs nyc (twitter.com) is all
    the time changing, and itt takes time aand effort to keep up with
    tendrncies and make one of the best decisions.

  21. Kayleigh says:

    These chilling decisions aree certain to evoke nostalgia aand get everybody into the
    halloween costumes 2016 ideas (Kayleigh)
    spirit.

  22. HueyUShumski says:

    Thanks for the marvelous posting! I certainly enjoyed reading it, you could be a fantastic author.I will
    make sure that I bookmark your website and will return in the foreseeable future.
    I wish to encourage you to continue your great job, use a nice holiday weekend!

    my blog post HueyUShumski

  23. Lord, make me an instrument of your peace where there is hatred, let me sow love where there is injury, pardon where there is doubt, faith where there is despair, hope where there is darkness, light and where there is sadness, joy.

Leave a Reply

Your email address will not be published. Required fields are marked *