htaccess gzip for Faster Loading and Bandwidth Saving

If you can use htaccess on your server and want to use gzip for faster Page Load Times / Bandwidth Saver. You can put the following lines in the htaccess file on your server:


<IfModule mod_gzip.c>
mod_gzip_on       Yes
mod_gzip_dechunk  Yes
mod_gzip_item_include file      \.(html?|txt|css|js|php|pl|jpg|png|gif)$
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.*
</IfModule>

This basically checks to see if mod_czip.c is found and if it is it will compress the files for you so they are faster to send to the browser. This supposedly speeds it up 35-40%. Then file sized supposedly go down 55-65%.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Technorati
  • Twitter
  • Yahoo! Bookmarks

About Shi Chuan

I am a web developer.
This entry was posted in HTTP Server and tagged . Bookmark the permalink.

12 Responses to htaccess gzip for Faster Loading and Bandwidth Saving

  1. Pingback: samaxes » .htaccess - gzip and cache your site for faster loading and bandwidth saving

  2. Pingback: .htaccess - gzip and cache your site for faster loading and bandwidth saving - samaxes

  3. Hey thanks but wondering if my host provider does not support this module?

  4. Kyle Welsby says:

    Thank you for this fantastic post :)

  5. Anthony says:

    Thanks for this!
    I am going to try this now.
    So in other words, If I have gzip uploaded to my server, I don’t have to do anything else besides add this to my .htaccess file?

  6. A says:

    “This basically checks to see if mod_czip.c is found”
    How do I go about making sure that mod_czip.c is found on my server? I download Gzip and uploaded, but I do not see mod_czip.c included in the file anywhere.

  7. Harry says:

    Great. Thanks. Using both of YSlow and Google page speed makes your posting valueable for me.

  8. Gzip is great for compressing files but don’t think that it’ll always be the best option for you. Gzip adds processing overhead to the server, specially since these pages aren’t cached and are gzipped on the fly. As bandwidth gets cheaper, it really doesn’t make sense to sacrifice precious server processing time on gzipping. I would recommend caching gzipped pages and using the htaccess to serve those if they exist in a directory (such as /cache )

  9. suvosaha says:

    Thanks for the code. But my shared host (hostgator) doesn’t support this module. please help me.

  10. Pingback: .htaccess – gzip and cache your site for faster loading and bandwidth saving | Ubuntu Viet

  11. Gopher says:

    If youry provider doesn’t have this module enabled, you can add the following line instead:

    php_value output_handler ob_gzhandler

    ………….this makes PHP to compress your PHP files.

  12. mdkkontrolle says:

    Thanks for sharing the code. Hope my hosting provider supports this… will check asap.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">