Skip to content

Commit

Permalink
[TalAter#30] Allow overriding default scope of ServiceWorker
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiker committed Aug 29, 2018
1 parent fe59134 commit eefaed6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/upup.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/upup.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/upup.zip
Binary file not shown.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ The settings object supports the following options:
- `cache-version` (String|Number) Optional version number, change this when offline files change. UpUp will download and cache all content-url and assets files again
- `service-worker-url` (String) The url to the service worker file (`upup.sw.min.js`)
Allows loading `upup.min.js` from a CDN while `upup.sw.min.js` stays local (see [scope](https://github.com/TalAter/UpUp/blob/master/docs/README.md#scope))
- `registration-options` (Object) An object containing registration options for ServiceWorkerContainer.register().

# API Reference

Expand Down
8 changes: 5 additions & 3 deletions src/upup.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
* - `cache-version` (String|Number) Optional version number, change this when offline files change. UpUp will download and cache all content-url and assets files again
* - `service-worker-url` (String) The url to the service worker file (`upup.sw.min.js`)
* Allows loading `upup.min.js` from a CDN while `upup.sw.min.js` stays local (see [scope](https://github.com/TalAter/UpUp/blob/master/docs/README.md#scope))
* - `registration-options` (Object) An object containing registration options for ServiceWorkerContainer.register().
*
* # API Reference
*/
Expand All @@ -125,7 +126,8 @@

// Settings live here, and these are their defaults
var _settings = {
'service-worker-url': 'upup.sw.min.js'
'service-worker-url': 'upup.sw.min.js',
'registration-options': {scope: './'}
};

var _debugState = false;
Expand Down Expand Up @@ -156,7 +158,7 @@
this.addSettings(settings);

// register the service worker
_serviceWorker.register(_settings['service-worker-url'], {scope: './'}).then(function(registration) {
_serviceWorker.register(_settings['service-worker-url'], _settings['registration-options']).then(function(registration) {
// Registration was successful
if (_debugState) {
console.log('Service worker registration successful with scope: %c'+registration.scope, _debugStyle);
Expand Down Expand Up @@ -203,7 +205,7 @@
}

// add new settings to our settings object
['content', 'content-url', 'assets', 'service-worker-url', 'cache-version'].forEach(function(settingName) {
['content', 'content-url', 'assets', 'service-worker-url', 'cache-version', 'registration-options'].forEach(function(settingName) {
if (settings[settingName] !== undefined) {
_settings[settingName] = settings[settingName];
}
Expand Down

0 comments on commit eefaed6

Please sign in to comment.