Skip to content

Commit

Permalink
Merge pull request #7 from miguelcobain/skip-waiting
Browse files Browse the repository at this point in the history
add skipWaiting call
  • Loading branch information
jkleinsc committed Nov 23, 2015
2 parents 74382b7 + 92530b4 commit fa188dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ writeServiceWorker(completeTree, {
],
dynamicCache: [
'/api/todos'
]
],
skipWaiting: true
});
```
Expand Down
9 changes: 8 additions & 1 deletion lib/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var BroccoliServiceWorker = function BroccoliServiceWorker(inTree, options) {
this.inTree = inTree;
options = options || {};
this.addPolyfill = options.addPolyfill || true;
this.skipWaiting = options.skipWaiting || false;
this.debug = options.debug || true;
this.dynamicCache = options.dynamicCache || [];
this.excludePaths = options.excludePaths || ['tests/*'];
Expand All @@ -26,6 +27,7 @@ BroccoliServiceWorker.prototype.constructor = BroccoliServiceWorker;

BroccoliServiceWorker.prototype.write = function(readTree, destDir) {
var addPolyfill = this.addPolyfill;
var skipWaiting = this.skipWaiting;
var debug = this.debug;
var dynamicCache = this.dynamicCache;
var fallback = this.fallback;
Expand Down Expand Up @@ -77,7 +79,7 @@ BroccoliServiceWorker.prototype.write = function(readTree, destDir) {

if (!stat.isFile() && !stat.isSymbolicLink())
return;
lines.push(createArrayLine("'"+file+"'", idx, array.length));
lines.push(createArrayLine(" '"+file+"'", idx, array.length));
});
lines.push("];");

Expand All @@ -87,6 +89,11 @@ BroccoliServiceWorker.prototype.write = function(readTree, destDir) {

//ServiceWorker code derived from examples at https://github.com/GoogleChrome/samples/tree/gh-pages/service-worker
addDebugLine("'Handling install event. Resources to pre-fetch:', urlsToPrefetch", debug, lines);

if (skipWaiting) {
lines.push(" if (self.skipWaiting) { self.skipWaiting(); }");
}

lines.push(" event.waitUntil(");
lines.push(" caches.open(CURRENT_CACHES['prefetch']).then(function(cache) {");
lines.push(" return cache.addAll(urlsToPrefetch.map(function(urlToPrefetch) {");
Expand Down

0 comments on commit fa188dc

Please sign in to comment.