Search code examples
http-headersbrowser-cachefetch-apilast-modified

How can I make my fetch requests include "Last-Modified" headers automatically?


I'm using fetch api (https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)

I'm getting a response with "Last-Modified" header (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified)

When I run the fetch a second time, it does not include the "Last-Modified" header in the request, and therefor fails at caching.


I have read the following on caching and fetch (https://developer.mozilla.org/en-US/docs/Web/API/Request/cache) but it works with ETags.


How can I make fetch include the "Last-Modified" header?


Solution

  • Last-Modified is a response header, not a request header.

    The corresponding request header is If-Modified-Since. That's what you should expect to see in the request if you want caching.