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

Make networkFirstResponse answer behaviour configurable #327

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

BowlingX
Copy link

@BowlingX BowlingX commented Dec 7, 2017

This pull requests addresses the issue described in #324.

@NekR
Copy link
Owner

NekR commented Dec 7, 2017

@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 :-)

@BowlingX
Copy link
Author

BowlingX commented Dec 12, 2017

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.

@BowlingX
Copy link
Author

@NekR is there more information necessary?

@NekR
Copy link
Owner

NekR commented Dec 15, 2017 via email

@BowlingX
Copy link
Author

BowlingX commented Apr 9, 2018

Any progress on this? @NekR

Sergei Buinov and others added 4 commits February 6, 2019 14:08
# Conflicts:
#	docs/options.md
#	lib/misc/sw-template.js
#	lib/service-worker.js
#	package.json
#	src/service-worker.js
#	tests/legacy/fixtures/basic-wIth-sw-out/__expected/sw.js
#	tests/legacy/fixtures/basic-with-sw-custom-entry/__expected/sw.js
#	tests/legacy/fixtures/cachemaps-basic/__expected/sw.js
#	tests/legacy/fixtures/loaders-externals/__expected/sw.js
#	tests/legacy/fixtures/sw-minify-false/__expected/sw.js
#	tests/legacy/fixtures/sw-minify-true/__expected/sw.js
Update from base repository
@BowlingX
Copy link
Author

@NekR we fixed the failing tests due to updates in the meantime. Is there anything else we can provide?

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

Successfully merging this pull request may close these issues.

None yet

2 participants