Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

By default, don't set an explicit scope in the SW registration. #83

Merged
merged 1 commit into from
Dec 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions platinum-sw-register.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,35 @@
},

/**
* The scope of the service worker, relative to the registered service worker script.
* All pages that fall under this scope will be controlled by the registered service worker.
* By default, the service worker will use a scope that applies to all pages at the same
* directory level or lower. This is almost certainly what you want, as illustrated by the
* following hypothetical serving setup:
*
* Normally, this would not need to be changed, unless you want the service worker to only
* apply to a subset of your site.
* ```
* /root/
* service-worker.js
* index.html
* subdir1/
* index.html
* subdir2/
* index.html
* ```
*
* So by default, registering `/root/service-worker.js` will cause the service worker's scope
* to cover `/root/index.html`, `/root/subdir1/index.html`, and /root/subdir2/index.html`.
*
* If, for some reason, you need to register `/root/service-worker.js` from within
* `/root/subdir1/index.html`, *and* you want that registration to only cover
* `/root/subdir1/**`, you can override this `scope` property and set it to `'./'`.
*
* There is more context about default scopes and how scope overrides work in
* [this Stack Overflow](http://stackoverflow.com/a/33881341/385997) response.
*
* @see {@link https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#navigator-service-worker-register}
*/
scope: {
type: String,
value: './'
value: null
},

/**
Expand Down Expand Up @@ -308,7 +326,8 @@
},

_registerServiceWorker: function(serviceWorkerUrl) {
navigator.serviceWorker.register(serviceWorkerUrl, {scope: this.scope}).then(function(registration) {
var options = this.scope ? {scope: this.scope} : null;
navigator.serviceWorker.register(serviceWorkerUrl, options).then(function(registration) {
if (registration.active) {
this._setState('installed');
}
Expand Down