remember

Ajax Tutorial

     Prototype, jQuery and another Ajax tutorials
 link: Go to the site
 host: tutorialajax.com
feed version: RSS 2.0
saved by: 0 member(s)
submitted by: ayaw
viewed: 69 time(s)
title: Ajax Tutorial
language: en
added: Aug 24, 2008
last crawled: Aug 24, 2008
 0 notes(s) for this feed 

Please login first
Forgot your password?
Not a member? Register.
remember
 1 feed(s) from tutorialajax.com
Newest Additions View ALL

Ajax Tutorial
Ajax Tutorial
     Prototype, jQuery and another Ajax tutorials


Compress JavaScript with Gzip

The main problem when we are using ajax framework is because of their big size. Of course, it will extremely slow down the sites load time. For example, if we use the standard jQuery, it’s almost 100Kb. It’s even more if we use the complete Prototype and Scriptaculous that will cost around 150Kb.

This is really nightmare for people who still use GPRS or the old 56kbps Dial-Up internet connection. It will takes minutes to load the sites or maybe it will takes forever because the browser usually won’t download it. Unfortunately, it’s very easy to solve this problem. Do you know that we can compress those files and reduce the size by half or more?

There are several method to compress javascript and I think one of the most efficient method is using Gzip Compression.

Gzip

To implement the gzip compression for websites, first we need to gzip the Javascript files. For that purpose, we will need a gzip-compatible archiver / compressor. 7-zip is my favorite because it’s small, very fast and it’s completely free.

Gzip the JavaScript file, change the “gz” extension to “jgz” for safari compatibility and upload it to the same location together with the original script. Then next, we must ask apache to get the compressed version if there is available and finally tell the browser to un-compress the file before it can be used.

To do that, we add these following code in our .htaccess

RewriteEngine on
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.jgz -f
RewriteRule (.*)\.js$ $1\.js.jgz [L]
AddType "text/javascript" .js.jgz
AddEncoding gzip .jgz

That’s all. Yeah.. And if you want to look for another method this is it.:





our sponsors:
- No win no fee solicitors
- Compare cheap Mortgages
privacy | terms | stats | copyright | advertise | contact
© feedest 2007-2008