Posts Tagged ‘Expires Header’

What Is An Expires Header And How Do I Add One?

Saturday, March 27th, 2010

An easy way to increase the speed of your site is to add an expires header. An expires header is a small piece of code that helps avoid the unnecessary download of data.

Unnecessary Download of Data

Each page on your site uses common files. Common files for running your fancy menu, common files for styling your links and header tags. By setting an expiration date on these files, you are telling browsers to download them once.
Do you have a company logo on every page? Your visitors should only be downloading it once. Until you decide to update, of course.

What Does The Expires Header Actually Do?

Adding an expiration date to certain files tells browsers that the data is ’still valid’. Data that is ’still valid’ does not need to be downloaded repeatedly.

What Should Expire?

Many file types should expire. Images, CSS sheets and Javascript files, for instance. If your website uses a drop-down menu, it is likely based on Javascript, CSS or Flash. This data should be downloaded once, not each time a page loads.

How To Add An Expires Header On An Apache Server

Add the following code to an .htaccess file in a root directory:

<FilesMatch “\.(ico|pdf|jpg|jpeg|png|gif|php|js|css)$”>
Header set Expires “Mon, 16 Apr 2019 20:00:00 GMT”
</FilesMatch>

This tells the browser of each visitor to download certain file types only once. Our code includes all sorts of images (jpg, png, gif) as well as our CSS, Javascript, PHP, PDF files and favicon (icon) files. It also tells browsers that the content is valid until April 2019. A far-future expires header is optimal. You want search engines to believe you have reliable content.

How To Add An Expires Header On A Microsoft Server

Not a fun process. We’re going to let an expert handle it. Follow this link.

The End Result

Each time a file is downloaded, it constitutes an HTTP request. The rule for HTTP requests is: the fewer the better. So the end result is fewer HTTP requests and expiration header data which leads to a faster site and the potential to rank higher because you’re efficiently serving up reliable content.