Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cache='reload' for precaching unversioned URLs #2146

Closed
jeffposnick opened this issue Jul 26, 2019 · 0 comments · Fixed by #2176
Closed

Use cache='reload' for precaching unversioned URLs #2146

jeffposnick opened this issue Jul 26, 2019 · 0 comments · Fixed by #2176
Assignees
Milestone

Comments

@jeffposnick
Copy link
Contributor

I'm spinning this off of #2143 (comment)

In Workbox v3, we used code like

_cacheBustRequest(request) {
let url = request.url;
const requestOptions = {
credentials: 'same-origin',
};
if ('cache' in Request.prototype) {
// Make use of the Request cache mode where we can.
// Reload skips the HTTP cache for outgoing requests and updates
// the cache with the returned response.
requestOptions.cache = 'reload';
} else {
const parsedURL = new URL(url, location);
// This is done so the minifier can mangle 'global.encodeURIComponent'
const _encodeURIComponent = encodeURIComponent;
parsedURL.search += (parsedURL.search ? '&' : '') +
_encodeURIComponent(`_workbox-cache-bust`) + '=' +
_encodeURIComponent(this._revision);
url = parsedURL.toString();
}
return new Request(url, requestOptions);
}

to cache-bust an outgoing request to populate the precache via setting the cache property to 'reload', with some feature detection to fall back to setting a cache-bust query parameter if needed.

In v4, we stopped that (partly because we end up using that query parameter as the actual cache key, so it's somewhat simpler to also use it in the outgoing request.)

We can change that, though, and potentially just set cache = 'reload' again. I did a quick check and it's supported in all modern browsers; you can check with:

fetch('https://httpbin.org/headers', {cache: 'reload'}).then(r => r.text()).then(console.log);

This might be done as part of a refactoring that would clear up some of our naming in workbox-precache around cacheKey and url.

CC: @philipwalton

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant