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

Skip cache on certain errors on network-first requests #324

Open
BowlingX opened this issue Dec 1, 2017 · 3 comments
Open

Skip cache on certain errors on network-first requests #324

BowlingX opened this issue Dec 1, 2017 · 3 comments

Comments

@BowlingX
Copy link

BowlingX commented Dec 1, 2017

Hi,
thank's a lot for this plugin :).
I'm wondering If it's possible to return the cached result only on certain error codes or even only if the client is offline. Right now, any error the server throws during fetch < 500 (like != ok -> https://github.com/NekR/offline-plugin/blob/master/src/misc/sw-template.js#L378) or general errors: https://github.com/NekR/offline-plugin/blob/master/src/misc/sw-template.js#L391 are forwarded to the cached version.

Could we make this configurable? I could properly provide a pull-request.

@BowlingX BowlingX changed the title Skip cache on certain errors on network-first request Skip cache on certain errors on network-first requests Dec 1, 2017
@NekR
Copy link
Owner

NekR commented Dec 3, 2017

@BowlingX that would be a good feature to have, but I'm not sure how API for that would look like. Do you have any ideas?

@GGAlanSmithee
Copy link
Collaborator

@BowlingX regarding returning cached assets only if the client is offline, you can do that already with responseStrategy

@BowlingX
Copy link
Author

BowlingX commented Dec 4, 2017

@GGAlanSmithee, At least network-first (see function networkFirstResponse) will always load from cache when != ok.

@NekR maybe something like:

shouldServeFromCache: (response:Object, cacheUrl:string, url:string) => boolean defaults to (response) => !response.ok

But I will think about something.

BowlingX added a commit to BowlingX/offline-plugin that referenced this issue Dec 7, 2017
BowlingX added a commit to BowlingX/offline-plugin that referenced this issue Dec 7, 2017
BowlingX added a commit to BowlingX/offline-plugin that referenced this issue Dec 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants