Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch API Cache Mode

According to the spec, there are various cache modes for the fetch api. ("default", "no-store", "reload", "no-cache", "force-cache", and "only-if-cached") However, it isn't clear what each mode is for, or the state of browser support.

like image 778
Daniel Herr Avatar asked Jul 24 '15 02:07

Daniel Herr


1 Answers

You can see the documentation of the polyfill here: https://fetch.spec.whatwg.org/

It does explain what each value means

"default" Fetch will inspect the HTTP cache on the way to the network. If there is a fresh response it will be used. If there is a stale response a conditional request will be created, and a normal request otherwise. It then updates the HTTP cache with the response. [HTTP]

"no-store" Fetch behaves as if there is no HTTP cache at all.

"reload" Fetch behaves as if there is no HTTP cache on the way to the network. Ergo, it creates a normal request and updates the HTTP cache with the response.

"no-cache" Fetch creates a conditional request if there is a response in the HTTP cache and a normal request otherwise. It then updates the HTTP cache with the response.

"force-cache" Fetch uses any response in the HTTP cache matching the request, not paying attention to staleness. If there was no response, it creates a normal request updates the HTTP cache with the response.

like image 146
alexmngn Avatar answered Sep 20 '22 10:09

alexmngn