Useful .htaccess Rules: Setting the expires header for browser caching

Posted in Notes on 22 February 2016

Expires headers let the browser know whether to serve 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.

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

 

Related Notes Posts

October 2024

What's going on between WordPress and WP Engine?

The disagreement between WordPress and WP Engine has sparked considerable debate within the WordPress community and could have important implications for users of the WordPress... Continue reading

August 2024

Guide to writing a good cookie policy (UK)

A cookie policy informs website visitors about the cookies your website uses, why they are used, and how users can control them. > **The information... Continue reading

May 2024

Email and newsletter deliverability best practice

Email deliverability refers to the ability of an email to successfully reach the recipient's inbox, rather than being marked as spam or bouncing back. High... Continue reading

More Notes Posts