Warning: Your browser is very out-of-date. You should upgrade to a better browser.

Expires headers let the browser know whether to server a cached version of the page. This can simultaneously help to reduce server load and increase page load time by telling the browser that it doesn’t have to check for new versions of files for an extended period.

The code below will allow images to be cached for a year and text-based content to be cached for one month. For most fairly static websites (like this one) that doesn’t change very often aside for a new post now and then this should be more then enough.

If you are running a dynamic website be careful with any sensitive information which may be stored, for example  JSON responses, user account pages and the like should be set-up to not cache.

## START keithgreer.dev EXPIRES CACHING ##
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
## END keithgreer.dev EXPIRES CACHING ##

The above can be copied into your .htaccess file without any major issues but, of course best checked before deploying to a live environment.

 

Hello, I'm Keith, a website developer in Belfast, Northern Ireland working with PHP, Magento, Shopify and WordPress.

I've been building websites for over 10 years, from custom website development to bespoke web applications, Shopify and Magento ecommerce and Online Leaning Environments. I've worked on a range of projects and am always looking out for the next interesting project.

Related Notes Posts

Notes August 2021

Apache VirtualHost with Reverse Proxy

This post documents the process of setting up a reverse proxy to load one (origin) website in the subdirectory of another. During this process the...
Notes June 2021

Upcoming changes to eBay's PayPal Payments

Over the course of 2021 eBay will be incrementally changing how it works with sellers. Changes include updates to the fee structure, how fees are...
Notes May 2021

Choose a better browser

Updated for 2020 A run down of the most popular web browsers including Firefox, Chrome, Edge and Opera as well some alternate options if you'd like something different....

More Notes Posts...