Skip to content

Commit

Permalink
NekR#324, make networkFirstResponse configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
BowlingX committed Dec 7, 2017
1 parent 0845c39 commit 0cdd470
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const defaultOptions = {
cache: void 0
},
minify: null,
shouldServeFromNetwork: (response) => response.ok,
navigateFallbackForRedirects: true
},

Expand Down
2 changes: 1 addition & 1 deletion src/misc/sw-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ function WebpackServiceWorker(params, helpers) {
function networkFirstResponse(event, urlString, cacheUrl) {
return fetch(event.request)
.then((response) => {
if (response.ok) {
if (params.shouldServeFromNetwork(response, urlString, cacheUrl)) {
if (DEBUG) {
console.log('[SW]:', `URL [${ urlString }] from network`);
}
Expand Down
4 changes: 2 additions & 2 deletions src/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class ServiceWorker {
this.minify = options.minify;
this.output = options.output.replace(/^\.\/+/, '');
this.publicPath = options.publicPath;

this.shouldServeFromNetwork = options.shouldServeFromNetwork;
this.basePath = null;
this.location = null;
this.pathRewrite = null;
Expand Down Expand Up @@ -185,7 +185,7 @@ export default class ServiceWorker {
},
externals: externals,
shouldServeFromNetwork: this.shouldServeFromNetwork,
hashesMap: hashesMap,
navigateFallbackURL: this.navigateFallbackURL,
navigateFallbackForRedirects: this.navigateFallbackURL ?
Expand Down

0 comments on commit 0cdd470

Please sign in to comment.