4

I was re-reading this great article and stumbled upon something I haven't noticed earlier, it's what the author calls Lazy Caching. To be precise here's the context:

Do they know how to use the Error Document to do lazy caching?

What is lazy caching and how error document is related to that? I have been googling these phrases rephrased and separated with no success.

Could someone explain what that is and where is used? I think there simply is a different name for that and I can't figure out what.

P.S. If you know how to better tag this question, please do so!

Sergey Telshevsky
  • 12,077
  • 6
  • 55
  • 78

1 Answers1

5

The "Error Document" is probably just referring to the HTTP status code, specifically the 304 Not Changed status. One might call it 'lazy caching' because on a static web site you usually wouldn't need to do anything to set it up.

How it would work on a static web site:

  1. Browser requests URL.
  2. Server returns response, including Last-modified: [last modified date of static file] header.
  3. Browser requests same URL later, including If-Modified-Since: [last modified date from first request] request header.
  4. Server returns 304 Not Modified response.

Since a dynamic page obviously can't rely on the modified date of a document, you do have to go out of your way to implement this sort of caching. It works exactly the same way, but rather than rely on the HTTP server to do anything automatically, you calculate the Last-modified date based on a database value (or whatever) and send that with every response. Then when you get a request containing an If-Modified-Since header, you can skip any processing after what is needed to calculate the last modified date and just send a 304 Not Modified response, potentially saving a ton of bandwidth and CPU cycles.

Here's an example in PHP to get you started if that's what you're looking for.

Kevin Stricker
  • 17,178
  • 5
  • 45
  • 71
  • Thank you, I'm not sure if it's related to 304 response because it says exactly "Error Document", but it also might be it as it's a good suggestion and the bounty is yours. – Sergey Telshevsky Feb 13 '13 at 07:57