Adding Expires Headers to a website

When your visitor revisits or browses through your website, all images and files have to be downloaded every time the page refreshes or changes.  If you add expires tags on all your files, you can effectively allow the browser to reuse what it has already downloaded without unnecessarily downloading the same file over and over effectively speeding up your website and saving on valuable bandwidth.

If you are looking to improve the load times of your website, to decrease server bandwidth, and to have a higher PageSpeed/Yslow score, then you should have the Expire tag built into all your files. Keep in mind that this tweak does not reduce first page load times, it only allows the browser to skip requesting the same files.  The browser will listen to your Expires Headers commands, and will not check for new updated files until the time you allocate has expired.  To reiterate, It simply tells the browser to use the data it has already downloaded from the first page it loaded, the landing page, and use that data throughout the visit on your website.  This means faster subsequent page loading and less bandwidth used on your server.  Java script, CSS, Menu Images, and regular repeating images like logos benefit the most from this.

The way I have choosen to integrate this into my website is simple.  You must find your .htaccess file and simply add the following lines to the bottom of it.  This tweak works great with Joomla to increase your users browsing experience.

    # Expire images header
    ExpiresActive On
    ExpiresDefault A0
    ExpiresByType image/gif A2592000
    ExpiresByType image/png A2592000
    ExpiresByType image/jpg A2592000
    ExpiresByType image/jpeg A2592000
    ExpiresByType image/ico A2592000
    ExpiresByType text/css A2592000
    ExpiresByType text/javascript A2592000

The "a2592000" specifies the time at which the file expires.  2592000 comes up to be 1 month.  That is how many seconds are in one month.  You can get whatever time you like by simply multiplication.  If you would like two weeks, you would take "60 seconds * 60 minutes * 24 hours * 14 days".  Each file type can have a different allocated time slot.  You can also add or remove any particular file type.  I generally make CSS and Javascript types expire in less time (example 1 week: 604800).  Really, there is no reason to have really long expires set.

UPDATE:: There is a newer, more current, way of setting expires headers in the your htaccess. I have outlined it below. You can make changes, sort the files types, and change the global age.

<filesMatch ".(jpg|jpeg|png|gif|ico|css|js)$">
Header set Cache-Control "max-age=2628000, public"

You can make changes, sort the files types, and change the global age.