Signin with : Openid login? Login through Ning.com

Compressing JavaScript (And Other Types) Using .htaccess

By: Taley 1 month ago : Comments (0)
In Internet

I became aware that Google was going to use speed (loading time) as a factor in website ranking. Search results will rank higher than a competitor if the page is faster (or so it is said). I started thinking about it and it was pretty stupid not to reduce the speed as much as possible regardless of Google's decision

The Apache Way....
I started with the normal steps and modified apache2.conf. I'm using Ubuntu and Webmin so my structure is a bit different than normal. Modules are loaded in a mods-enabled folder in /etc/apache2/. mod_deflate was already being loaded into apache and I confirmed it. So I added these lines to my site configuration (held in /etc/apache2/enabled-sites):


<location>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/x-js text/css
</location>


I analyzed my website and it still did not work.  So I thought it was the mime types. I realized that it was x-javascript so I added:

<location>
    AddOutputFilterByType DEFLATE application/x-javascript
</location>


After restarting apache, it still did not work.  


The .htaccess Way....
I found a blog post that had a similar problem. The  writer, Scott, suggested adding this to .htaccess:

<ifmodule deflate_module="">
    <filesmatch> 
        SettOutputFilter DEFLATE 
     </filesmatch> 
</ifmodule>


After adding that and analyzing my website again, compression was found on all JavaScript files! Prototype was reduced to a mere 20k. My website was faster (loading at 60 seconds on dial-up). 

Sources:
http://www.techiegyan.com/?p=251
http://www.webperformancer.com/2009-08-31/configuring-apache-server-gzip-compression/
http://www.opensourcetutor.com/2009/06/01/how-to-compress-css-javascript-an-alternative-to-mod_deflate-or-mod_gzip/
http://joseph.randomnetworks.com/archives/2006/07/13/compressed-javascript/

  • Total views:  660
  • Total comments:  0

Rate Now: 1 2 3 4 Average Rating: 0.00 / 0 ratings

No comments posted