1 week, 7 days, 168 hours, 10,080 minutes and 604,800 seconds

Some short, but useful reminder.

I often forget how long it is 604,800 seconds. The last time it was necessary to expose HTTP response headers in my job.

1 week, 7 days, 168 hours, 10,080 minutes and 604,800 seconds

Therefore, I am doing an easy and simple bookmark for everyone :). You can already see the detailed result in the title –
1 Week, 7 days, 168 hours, 10,080 minutes and 604,800 seconds.

Using 604,800 seconds in cache headers

The number comes up most often when you set up browser caching. The Cache-Control header tells the browser how long it can keep a file before downloading it again, and the max-age value is always set in seconds. To cache a file for one week, use:

Cache-Control: public, max-age=604800

Common max-age values:

  • 1 hour = 3,600 seconds
  • 1 day = 86,400 seconds
  • 1 week = 604,800 seconds
  • 30 days = 2,592,000 seconds
  • 1 year = 31,536,000 seconds

Which value to choose depends on how often a file changes. Images, fonts, CSS, and JavaScript files with a version number or hash in their name can be cached for a year, often with the immutable directive added. Files that change without getting a new name, such as a stylesheet you edit in place, are safer with a shorter period like a week. HTML pages usually get a short max-age or no-cache, so visitors always see the latest content.

On Apache servers, you can set these values in the .htaccess file with the mod_expires or mod_headers module. In WordPress, most caching plugins let you set browser cache times without editing server files. To check which value a file uses, open your browser’s developer tools, go to the Network tab, select the file, and look for Cache-Control under Response Headers.

Cache-Control directives at a glance

Besides max-age, a few other directives control how a file is cached:

  • public: any cache, including a CDN, may store the response.
  • private: only the visitor’s browser may store it, which suits pages with personal data.
  • no-cache: the browser may store the file but must check with the server before using it again.
  • no-store: nothing is stored at all, which is the right choice for sensitive pages.
  • immutable: the file will never change, so the browser doesn’t recheck it while max-age is valid.
  • s-maxage: works like max-age but applies only to shared caches such as a CDN, so you can cache longer there than in browsers.

You can combine several directives in one header, separated by commas:

Cache-Control: public, max-age=31536000, immutable

If a page stays out of date after an update, check its headers first: a long max-age on HTML is a common reason visitors keep seeing an old version.

// discussion

No comments yet — be the first

Leave a comment

// your email stays private. Required fields marked with an asterisk.