fetch(), how to make a non-cached request?
P粉214176639
2023-08-27 18:47:06
<p>Using <code>fetch('somefile.json')</code>, can I request a file from the server instead of the browser cache? </p>
<p>In other words, is it possible to bypass the browser's cache using <code>fetch()</code>? </p>
Easier use of cached mode:
Reference: https://hacks .mozilla.org/2016/03/referrer-and-cache-control-apis-for-fetch/
Fetch You can get an init object that contains many customizations you might want to apply to your request, including an option called "Headers".
The "headers" option takes a Header object. This object allows you to configure headers to be added to the request.
By adding pragma: no-cache and cache-control: no-cache in the header, you will force the browser to check the server to see if the file exists with the cache are different from the existing files in . You can also use cache-control: no-store as it just doesn't allow the browser and all intermediate cache stores to return any version of the response.
Here is a sample code: