.htaccess – Gzip and Expires and a Cache-Control to your website site for faster loading

To speed up my site and save bandwidth, I use .htaccess file to gzip my text based files and optimize cache HTTP headers.

Turn on compression

mod_gzip is an external expansion method for Apache that allows you to quickly constrict your information before you send them to the users browsers.

If your in linex hosting and it has mod_gzip module enabled, the easy way to compress is to add the following code to your .htaccess file:

or, DEFLATE method

Add an Expires and a Cache-Control Header

Website designs are getting rich and fast, which means more scripts, CSS, images, and Flash in the site. A first-time visitor to your web page makes HTTP requests, but by using the Expires header you make those elements cacheable. This prevents unnecessary HTTP requests and Bandwidth. Expires headers are most often used with images, but they should be used on all elements including JS, CSS, and Flash elements.

To set your Expires headers add these lines to your .htaccess:

To set Cache-Control headers add these lines to your .htaccess:

If you can’t change your .htaccess file, you can use PHP to return compressed content. Give your HTML file a .php extension and add this code to the top

Turn off ETags

By removing the ETag, you disable caches and browsers from being able to validate information, so they are forced to depend on your Cache-Control and Comes to an end headlines.
Entity meta data (ETags) are a process to check for a modern edition of a cached file.

Add these lines to .htaccess:

Remove Last-Modified header

If you remove the Last-Modified and ETag, you will completely get rid of If-Modified-Since and If-None-Match needs and their 304 Not Customized responses, so a page file will remain cached without verifying for up-dates until the Comes to an end Expires header indicates new content is updated.

Add these lines to .htaccess: