From f27ec5c2d22c0ac0ddaeaf3372efd1db90ed7c4b Mon Sep 17 00:00:00 2001 From: Jeff Posnick Date: Thu, 10 Dec 2015 11:05:27 -0500 Subject: [PATCH] By default, don't set an explicit scope in the SW registration. --- platinum-sw-register.html | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/platinum-sw-register.html b/platinum-sw-register.html index e4984f7..89ab6c0 100644 --- a/platinum-sw-register.html +++ b/platinum-sw-register.html @@ -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 }, /** @@ -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'); }