Compressing your website files, especially the text files, with mod_gzip or mod_deflate on Apache not only save heaps of network bandwidth, but also speed up downloading your website up to 70%.
Most web servers can compress hosted website files in gzip format before sending them for download. To enable compression, configure your web server to set the Content-Encoding header to gzip format for all textual resources.
Almost all modern browsers support data compression for HTML, CSS, and JavaScript files. This allows web servers to send data over the network in compressed form and help in reducing lot of network traffic and download time.
Apart from the gzip compression, you can also use deflate. Here’s a sample code that you can place in the .htaccess file at root of your website:
Enable file compression using mod_gzip
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
Enable file compression using mod_deflate
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
There are few caveats here. Compression needs processor usage and compressing media files is not recommended for following reasons:
- Usually media files are already optimized and there is not much to gain by compressing them.
- Media files such as mp3s, videos, images etc. are much larger in size and hence require more processor power out weighing the benefits of compressing them.
Check and Confirm Your Compression
Once you have added code in the .htaccess on your server, check it to make sure it’s actually serving up compressed files. you can verify it in several ways:
- Use the online gzip tool to check if your web page is compressed or not.
- You can install Google PageSpeed Firefox Addon and see whether your web page is compressed or not.
Hope that helps.
Cheers!
Is it possible to enable the GZIP compression only for a single application ? My apache web server is having multiple applications is the potal and i want this compression to be enabled for one. i.e. the above configuration should be application specific. Is that possible ? Please let me know.
Yes, copy all this code to the .htacess file in that folder. These instructions will only work then for that directory and all those below it.
gidnetwork actually doesn’t test all components of your page
better use http://siteloadtest.com