By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

It pays to configure your caching headers

Caching can sometimes improve the load times of your pages.

Created: 2012-03-02 13:31

Caching is one of the easier ways that you can improve the load times of your pages, and you may even save some bandwidth in the process.

Caching works by preventing additional requests for content that has already been downloaded. What you would typically do to prevent requests, is to set an expatriation date for certain static resources, and ensure that dynamically delivered resources are validated properly with the HTTP If-modified-since.

Expiration Dates

Setting an expiration date far into the future for JavaScript, CSS, images, and other files which doesn't change very often. For CSS and JavaScript files, you can include a version number in the file names, to always ensure that users have the latest versions. I.e.

main-styles-v1.1.css

Conditional requests

Dynamic content includes any content delivered trough a CMS, what you want to make sure, is that browsers correctly performs a conditional request for your page. If the content or CMS it self has been updated, then the server should respond with a 200 Ok code, and the content should be re-downloaded. If nothing changed, then the server should respond with a 304 Not Modified code, and the resource should be fetched from the browsers cache.

See also

  1. Using HTTP IF MODIFIED SINCE with PHP
  2. Must-revalidate not working as expected