Set Expire Headers using .htaccess

Avinash

9

Aug 31, 2011

Web Server

It is a good practice to set the expire header for the static content like css, images and js files.

When you set the far future expire days for the static content then browser will serve those resource from the cache till that date. So it recommeded to set the far future date for the content which not changes frequently.

For setting up the expire header via htaccess you need to enable mod_expire module of the apache. Let’s see how we can set the Expire Headers using .htaccess

I generally use trick provided by the HTML5BoilerPlate for setting up the expire header for the static content.

Avinash Zala currently working at a leading web development company as a Sr. PHP Web Developer. He is the founder of the Xpert Developer. He has completed B.E. in Information Technology. Born and brought up in Ahmedabad. He loves to code and coding is all about passion for him. Follow him on twitter at Avinash Zala & Xpert Developer.

Hey! finally a good place to learn how to speed out my site. Thank you very much…

I got a couple of questions if you don’t mind.
1. What’s the difference between this method to the one in your other post “Tips to speed up website and get high ranking in ySlow’

2. How do I set gzip for js, css and content on my site ? I’m stlling checking with my host about their Apache version to know whater to use gzip or deflate mod, as far as I understood from reading on yahoo dev page.

Thanks!

http://www.xpertdeveloper.com Avinash

Hi Sam,

Answers to your questions:

1) This article explain how to set expire headers to make your content cached. And the earlier article shows various tricks to get high ranking in ySlow along with the performance.

2) I am sure that your host will have Apache 2 or above, so you can use defalte. as gZip was supported upto Apache 1.3. Regarding the compressing it will be my next article: Subscribe via email to get latest updates