'Navigate in JavaScript but adjust the `Cache-Control` header
I have a timeout of 5 seconds to detect if one is offline.
If a user tries an AJAX POST and they are offline, it will timeout after 5 seconds, and then the AJAX POST fails. When the AJAX POST fails, I wish to perform a navigation to a different URL, but because I know the server is down, I wish to tell the Service worker, don't try query the server, and waste another 5 seconds, just hit the cache (the response will be pre-cached).
To tell the service worker to hit the cache from my research the most "correct" way seems to be set the Cache-Control header to only-if-cached.
How does one perform:
window.location.replace(url);
But set the Cache-Control header?
At the moment a failed AJAX POST takes 10 seconds to handle, whereas it should only take 5 seconds.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
