4

I'm reading this article on Azure CDN. I can either control caching with:

  1. An ETag
  2. Last Modified
  3. Default heuristics

What are the benefits and drawbacks of the first two choices? Does it matter?

Places where one might work vs the other could be:

  • Cross domain calls
  • Private browsing
  • IFrames
  • Ajax

... where that data is either visible by those methods, and not the others.

makerofthings7
  • 8,821
  • 28
  • 115
  • 196

2 Answers2

0

Both are valid to use in whatever scenario.
eTag is newer so it is considered best practice to use that instead of last-modified, however it is up to you.
Here is the MS Docs page explaining that eTag takes precedence over last-modified in which system interprets it:
https://docs.microsoft.com/en-us/azure/cdn/cdn-how-caching-works#cdn-caching

Elliot Huffman
  • 1,169
  • 1
  • 10
  • 22
0

Let me make two real-life assumptions:

  • you cannot easily customize the code that generates ETag or Last-Modified for you
  • you are serving some static files

with this in mind, the most obvious difference is that for files, it's easy for you to either accidentally or purposely change the modification date, thus changing Last-Modified header. (You could even, gasp, return to an earlier date.) In general case, you cannot impact ETag so easily. Good or bad? Depends on your use case. If the code that generates ETag is decent, I'd say it is better suited to a general use case aka just-works-out-of-the-box-dont-touch-the-knobs. But to know whether it's decent requires testing, especially testing upgrades and downgrades.

ETag is good for content that changes more than once per second (example: a heavily used chat), because Last-Modified only supports 1-second granularity.

ETag for compressed response should be re-generated by your server, it cannot be copied from uncompressed one. But it's much less CPU usage than compressing anyway.

With CORS, youu have Last-Modified for free, but to have eTag your server needs to support an extra header Access-Control-Expose-Headers: ETag (MDN).

kubanczyk
  • 13,502
  • 5
  • 40
  • 55