Make `networkFirstResponse` answer behaviour configurable
This pull requests addresses the issue described in #324.
@BowlingX There should be tests for each feature added. Also, can you write an usage example so we all could clearly understand how the feature will be used? An real world example would be great :-)
Real world usecase:
Imagine having the following configuration:
const config = {
/*...*/
externals: ['/de-de', '/en-en'],
cacheMaps: [{
match: function match(requestUrl) {
const localeMatch = requestUrl.pathname.match(/(\/[a-z]{2}-[a-z]{2})(.*)/);
if (localeMatch && localeMatch[1]) {
return new URL(localeMatch[1], location);
}
},
requestTypes: ['navigate']
}]
/*...*/
}
The configuration defines 2 external sites (based on the locale) as appshell. It will serve any request that matches the pattern with the locale and falls back to /de-de or /en-en respectively. (e.g. /de-de/some/path -> /de-de if offline etc.)
Right now the uncached response will only be forwarded if the server's response is in the 2xx range (that's what's response.ok is meaning). If the server responds with a 301 / 302 or any error (4xx, 5xx etc.) it will fallback to the cached version. This is not what I want if the server is reachable. The Appshell should only be loaded on a failed request if offline.
In my case, the Page is rendered on the server as well and prepopulated with data and/or might even be redirected. When the user visits the page for the first time this will work, but in case he already downloaded the assets, the page will not redirect or error / not found. It will show the cached version of /de-de for example.
@NekR is there more information necessary?
I don't really have time to handle this week, sorry. I think provided info is enough and use cases are good. I'll review the code/api next week and merge if everything is good. Thanks for making this PR!
On Dec 15, 2017 2:50 PM, "David Heidrich" [email protected] wrote:
@NekR https://github.com/nekr is there more information necessary?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NekR/offline-plugin/pull/327#issuecomment-351987420, or mute the thread https://github.com/notifications/unsubscribe-auth/ABIlkfDcac4Bec9NquL6kCZ4-8waTmsSks5tAl0SgaJpZM4Q5i23 .
Any progress on this? @NekR
@NekR we fixed the failing tests due to updates in the meantime. Is there anything else we can provide?