Polymer / polymer-starter-kit

A starting point for Polymer apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rootPath setting won't work in 3.x

arthurevans opened this issue · comments

Currently the 3.x branch retains this code from 2.x:

window.Polymer = { rootPath: '/' };

(See the comment starting at:
https://github.com/Polymer/polymer-starter-kit/blob/3.0-preview/index.html#L64)

This will work in the SW register call that follows, but it will not set the Polymer rootPath variable like it did in 2.x. To do that, You'd need to load the settings module and manually set the property.

<script type="module">
import {rootPath} from '@polymer/polymer/lib/utils/settings.js';

rootPath = '/';

// Load and register pre-caching Service Worker
if ('serviceWorker' in navigator) {
  window.addEventListener('load', function() {
    navigator.serviceWorker.register('service-worker.js', {
      scope: Polymer.rootPath
    });
  });
}
</script>

That assumes, of course, that you can register a service worker from an ES module. Haven't tried.

Assuming we change this, we should also update the code in the tools/serviceworker docs on p-p.org.

This should be fixed after #1112.