Cache-Control and Last-Modified and ETag, oh my! @ Kansas City Developer Conference

Cache-Control and Last-Modified and ETag, oh my! @ Kansas City Developer Conference

Ever wonder exactly what combination of Cache-Control, Last-Modified, Expires, ETag, Vary, and Pragma headers will keep your content cached by browsers just long enough? And what exactly is a HTTP 304 anyway?

In this talk, we’ll take a look around at the available HTTP caching headers, what their values mean, and how browsers and proxies react. We’ll cover the best practices on client cache invalidation, the benefits of sending a Not Modified response, and briefly talk about the changes in HTTP 2.0 (SPDY) around caching.

2e055eb589fb86174fd268748b0fcd30?s=128

Andrew Dunkman

May 17, 2014
Tweet

Transcript

  1. Cache-control and Last-Modified and ETag, Oh My! ! @adunkman

  2. Expires, Pragma, Vary Cache-Control Conditional Requests A Few Tips The

    Future of Caching
  3. Expires, Pragma, Vary Cache-Control Conditional Requests A Few Tips The

    Future of Caching
  4. Wed, 14 May 2014 22:36:20 GMT

  5. Pragma: no-cache

  6. Pragma: no-poll

  7. Vary: User-Agent

  8. Expires, Pragma, Vary Cache-Control Conditional Requests A Few Tips The

    Future of Caching
  9. Expires, Pragma, Vary Cache-Control Conditional Requests A Few Tips The

    Future of Caching
  10. no-cache no-store no-transform

  11. max-age s-maxage

  12. must-revalidate proxy-revalidate max-stale

  13. private public

  14. no-cache! no-store! no-transform! max-age! s-maxage! must-revalidate! proxy-revalidate! max-stale! public! private

  15. Quiz

  16. Expired responses ! will not be cached. _FALSE_

  17. It’s perfectly okay! to set an Expires header! 30 years

    in the future. _FALSE_
  18. If a response has both! Expires: <now + 1 year>!

    and! Cache-Control: max-age=15! how long is it cached?
  19. Expires, Pragma, Vary Cache-Control Conditional Requests A Few Tips The

    Future of Caching
  20. Expires, Pragma, Vary Cache-Control Conditional Requests A Few Tips The

    Future of Caching
  21. Last-Modified! If-Modified-Since

  22. Etag! If-None-Match

  23. Expires, Pragma, Vary Cache-Control Conditional Requests A Few Tips The

    Future of Caching
  24. Expires, Pragma, Vary Cache-Control Conditional Requests A Few Tips The

    Future of Caching
  25. Always changing:! prevent caching.

  26. Cache-Control: no-cache

  27. May change:! prevent using a cache! without revalidation first.

  28. Expires: <in the past>! Cache-Control: must-revalidate, max-age=0

  29. Never changes:! Cache forever*.

  30. Expires: <1 year from now>! Cache-Control: max-age=31556926

  31. Be careful what ! you say in public.

  32. Vary: Accept-Encoding

  33. example.com?but_why=lame

  34. Expires, Pragma, Vary Cache-Control Conditional Requests A Few Tips The

    Future of Caching
  35. Expires, Pragma, Vary Cache-Control Conditional Requests A Few Tips The

    Future of Caching
  36. <link rel=“prefetch” href=“…”>

  37. Link: <url>; rel=prefetch

  38. <link rel=“subresource” … >

  39. Link: <url>; rel=subresource

  40. SPDY

  41. mod_spdy

  42. X-Associated-Content: ! "full-url":<priority>

  43. Expires, Pragma, Vary Cache-Control Conditional Requests A Few Tips The

    Future of Caching
  44. Thank you! ! @adunkman