Wednesday, November 04, 2009

Compress all output and speed up download big js files

We can speed up downloads or web page access time with Apache mod_deflate module. The mod_deflate module provides the DEFLATE output filter that allows output from our server to be compressed before being sent to the client over the network.

This decreases the amount of time and data transmitted over the network, resulting in faster web experience or downloads for visitors.

Today we add the following config in our Apache server,

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript application/javascript

And our js file size are huge reduced. The big one reduce as follow:

ext-all.js - from 609 k to 167 k
home_mini.js - from 523 k to 101 k

It makes our site load really quick and it is really help. You can try it at our site: www.feyasoft.com

Notice

Enabling filters with AddOutputFilterByType may fail partially or completely in some cases. For example, no filters are applied if the MIME-type could not be determined and falls back to the DefaultType setting, even if the DefaultType is the same.

However, if you want to make sure, that the filters will be applied, assign the content type to a resource explicitly, for example with AddType or ForceType. Setting the content type within a (non-nph) CGI script is also safe.

Ok, here are the details steps to create it:

# cd /usr/local/apache/config/
# vi httpd.conf
Add the following line:

LoadModule deflate_module modules/mod_deflate.so
< Location / >
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript application/javascript
< /Location >
And now your need restart apache. If you did not have mod_deflate.so in your apache. Ok, now you need config and build one from apache source code. Here is a good link for your:

http://streetsmartingit.blogspot.com/2007/11/how-to-compileinstall-moddeflate-into.html

No comments: