Search This Blog

Tuesday, November 13, 2018

Browser Caching: Expires and Cache-Control: max-age headers

Expires and Cache-Control: max-age headers specify the time period during which the browser can use the cached resource without checking to see if a new version is available from the web server. They are "strong caching headers" that apply unconditionally. Once they're set and the resource is downloaded, the browser will not issue any GET requests for the resource until the expiry date or maximum age is reached or the cache is cleared by the user.

Expires is preferred over Cache-Control: max-age because it is more widely supported. Do not set it to more than one year in the future, as that violates the RFC guidelines.

These headers for browser caching are to be enabled on your server. Static resources should have a cache lifetime of at least a week. For third-party resources like ads or widgets, they should have a cache lifetime of at least one day.