MicroPosts

  • HTTP cache cookbook

    Flow chart: Reusable response? No: no-store. Yes: Revalidate each time? Yes: no-cache and continue to No: Cacheable by intermediate caches? No: private and continue. Yes: public and continue. Maximum cache lifetime? max-age=x & use ETag.

    Examples:

    • Fingerprinted URLs
      • Want: allow intermediate caches (not only browser) to cache for a year and after that revalidate with ETag
      • Use: Cache-Control: public, max-age=31536000 and configure ETag header in server's responses
    • Mutable content
      • Want: Always revalidate with ETag
      • Use: Cache-Control: no-cacheAND configureETag`

    What's the difference between no-cache vs must-revalidate + max-age?

    • no-cache requires client to ALWAYS check if content is fresh (e.g., with ETag or Last-Modified)
    • must-revalidate + max-age allows the cache to serve cached content until max-age is reached

    Why using Cache-Control: must-revalidate, max-age=600 is a bad idea for mutable content?

    If that Url serves an Html that fetches additional assets (e.g., Js, Css) with the same cache strategy, the cache may load Html and Css and the server may load Js which refers to the newer (not cached) Html and Css.

    Source: Prevent unnecessary network requests with the HTTP Cache

PinkLetter

It's one of the selected few I follow every week – Mateusz

Tired of RELEARNING webdev stuff?

  • A 100+ page book with the best links I curated over the years
  • An email once a week full of timeless software wisdom
  • Your recommended weekly dose of pink
  • Try before you buy? Check the archives.