I’ve talked a lot about why speed matters when it comes to your website’s load time (see my full guide on how to speed up your website for more information).
Today we’re going to narrow in on one easy way which is how to add expires headers.
The basic gist of why it’s so important is that slow websites alienate your traffic which in turn alienates search engines like Google from giving you a nice ranking.
Google wants to offer up the best experience to their users, and if your website takes several seconds to load up, then you don’t qualify regardless of the strength of your content.
I put together a resource on how to check your website’s speed, and in it I mention a couple tools such as Pingdom and GTMetrix.
If you plug your website in one of those tools, you’ll get a speed score and a few recommendations of what you can do to improve your speed.
One of these may be “add expires headers”.
This just means to specify on your website that you want certain file types to cache for longer amount of time than others, meaning that upon subsequent visits to your site, your visitors’ browsers won’t have to reload the files you’ve specified.
It’s wise to specify this for a number of file types which are generally static and don’t need to be updated frequently.
Now let’s actually talk about how to fix add expires headers.
How to Add Expires Headers
Fortunately this is simply a matter of navigating to your .htaccess file which is located in the root directory of your website, opening it up, and pasting the following code at the bottom:
<FilesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css|woff)$">ExpiresActive OnExpiresDefault A2592000</FilesMatch>
This signals to your visitor’s browser that it can cache the listed file types (CSS, JPG, JS, etc.) for the period of time listed.
In this example’s case, the length of time is 2592000 seconds, or the equivalent of 30 days.
After those 30 days, if the visitor returns to your website, the files will refresh, but in the meantime everything will load much quicker as it’s been cached.