anon
anon

Reputation:

Does the cache for fetch need to be managed by the client?

When fetching data with a polyfilled fetch, I'm getting a 304 response as described here. Fetch apparently automatically generates the appropriate If-None-Match header for my request, and my backend replies with a 304 (data is already in cache). The request isn't properly fullfilled though.

I couldn't find any documentation on where this cached data can be found though. So should the cached data be retrieved automatically? I could set a 'cache-control': 'no-cache' header, but I'd prefer to use caching of course.

Upvotes: 2

Views: 789

Answers (1)

scunliffe
scunliffe

Reputation: 63646

If I understand what you're asking, if the server returns a 304 for the request that the browser sent to it, then the browser fulfills the request from it's cache (depends on the browser) just as it does for any normal HTTP Request or XMLHTTP Request.

If however you do not want to get content from the cache, and you want to force a brand new load of content, you will want to set the applicable 'cache-control': 'no-cache' header AND ensure that the URL you are trying to fetch is unique (either by path or parameters). Often the easiest way to do this is append a dummy param with the current timestamp. e.g. ...&_=1483970310923

Upvotes: 2

Related Questions