Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Feature request: support cache busting via query params #198

Open
markbrocato opened this issue Oct 10, 2016 · 1 comment
Open

Feature request: support cache busting via query params #198

markbrocato opened this issue Oct 10, 2016 · 1 comment

Comments

@markbrocato
Copy link

Apps often make requests like "/api/users?_dc=123456789", where _dc is the timestamp at which the request is generated and is used to prevent caching. This always results in a cache miss when using sw-toolbox. When it is desirable to fetch fresh data from the server when connected to the network, but fall back on the last cached response when offline, it would be great if there was a way read from the cache for /api/users when /api/users?_dc=123456789 fails to connect.

The sw-precache library already contains a similar option called ignoreUrlParametersMatching. Building on that, one could imagine the following:

toolbox.router.get(/api\/users/, toolbox.networkFirst, { ignoreUrlParametersMatching: /^_dc$/ })

@mudcube
Copy link

mudcube commented Oct 11, 2016

Hey Mark, that would be an awesome pull-request. I did a quick look through the codebase, and it looks like the place where the query strings are being ignored is in /lib/router.js on line 98. Where it says var path = urlObject.pathname. For example, to always treat query strings as their own unique requests you would modify this line to read: var path = urlObject.pathname + urlObject.search. Hopefully this helps get you started.

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

No branches or pull requests

2 participants