diff --git a/dist/upup.min.js b/dist/upup.min.js index 65c99fe..b7b1e87 100644 --- a/dist/upup.min.js +++ b/dist/upup.min.js @@ -3,5 +3,5 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://github.com/TalAter/UpUp -(function(e){"use strict";var t=navigator.serviceWorker;if(!t)return this.UpUp=null,e;var n={"service-worker-url":"upup.sw.min.js"},r=!1,s="font-weight: bold; color: #00f;";this.UpUp={start:function(e){this.addSettings(e),t.register(n["service-worker-url"],{scope:"./"}).then(function(e){r&&console.log("Service worker registration successful with scope: %c"+e.scope,s);(e.installing||t.controller||e.active).postMessage({action:"set-settings",settings:n})}).catch(function(e){r&&console.log("Service worker registration failed: %c"+e,s)})},addSettings:function(t){"string"==typeof(t=t||{})&&(t={content:t}),["content","content-url","assets","service-worker-url","cache-version"].forEach(function(r){t[r]!==e&&(n[r]=t[r])})},debug:function(e){r=!(arguments.length>0)||!!e}}}).call(this); +(function(t){"use strict";var e=navigator.serviceWorker;if(!e)return this.UpUp=null,t;var i={"service-worker-url":"upup.sw.min.js","registration-options":{scope:"./"}},o=!1,n="font-weight: bold; color: #00f;";this.UpUp={start:function(t){this.addSettings(t),e.register(i["service-worker-url"],i["registration-options"]).then(function(t){o&&console.log("Service worker registration successful with scope: %c"+t.scope,n);(t.installing||e.controller||t.active).postMessage({action:"set-settings",settings:i})}).catch(function(t){o&&console.log("Service worker registration failed: %c"+t,n)})},addSettings:function(e){"string"==typeof(e=e||{})&&(e={content:e}),["content","content-url","assets","service-worker-url","cache-version","registration-options"].forEach(function(o){e[o]!==t&&(i[o]=e[o])})},debug:function(t){o=!(arguments.length>0)||!!t}}}).call(this); //# sourceMappingURL=upup.min.js.map \ No newline at end of file diff --git a/dist/upup.min.js.map b/dist/upup.min.js.map index 782eab1..b02b382 100644 --- a/dist/upup.min.js.map +++ b/dist/upup.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/upup.js"],"names":["undefined","_serviceWorker","navigator","serviceWorker","this","UpUp","_settings","service-worker-url","_debugState","_debugStyle","start","settings","addSettings","register","scope","then","registration","console","log","installing","controller","active","postMessage","action","catch","err","content","forEach","settingName","debug","newState","arguments","length","call"],"mappings":";;;;;CAMA,SAAWA,GACT,aAyGA,IAGIC,EAAiBC,UAAUC,cAK/B,IAAKF,EAEH,OAVUG,KASJC,KAAO,KACNL,EAIT,IAAIM,GACFC,qBAAsB,kBAGpBC,GAAc,EACdC,EAAc,kCAnBNL,KAsBNC,MAoBJK,MAAO,SAASC,GACdP,KAAKQ,YAAYD,GAGjBV,EAAeY,SAASP,EAAU,uBAAwBQ,MAAO,OAAOC,KAAK,SAASC,GAEhFR,GACFS,QAAQC,IAAI,wDAAwDF,EAAaF,MAAOL,IAI1EO,EAAaG,YAAclB,EAAemB,YAAcJ,EAAaK,QAC3EC,aAAaC,OAAU,eAAgBZ,SAAYL,MAE5DkB,MAAM,SAASC,GAEZjB,GACFS,QAAQC,IAAI,yCAAyCO,EAAKhB,MAyBhEG,YAAa,SAASD,GAII,iBAHxBA,EAAWA,SAITA,GAAYe,QAAWf,KAIxB,UAAW,cAAe,SAAU,qBAAsB,iBAAiBgB,QAAQ,SAASC,GACvFjB,EAASiB,KAAiB5B,IAC5BM,EAAUsB,GAAejB,EAASiB,OAaxCC,MAAO,SAASC,GAEZtB,IADEuB,UAAUC,OAAS,MACLF,MAQrBG,KAAK7B","file":"upup.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/upup.js"],"names":["undefined","_serviceWorker","navigator","serviceWorker","this","UpUp","_settings","service-worker-url","registration-options","scope","_debugState","_debugStyle","start","settings","addSettings","register","then","registration","console","log","installing","controller","active","postMessage","action","catch","err","content","forEach","settingName","debug","newState","arguments","length","call"],"mappings":";;;;;CAMA,SAAWA,GACT,aA0GA,IAGIC,EAAiBC,UAAUC,cAK/B,IAAKF,EAEH,OAVUG,KASJC,KAAO,KACNL,EAIT,IAAIM,GACFC,qBAAsB,iBACtBC,wBAAyBC,MAAO,OAG9BC,GAAc,EACdC,EAAc,kCApBNP,KAuBNC,MAoBJO,MAAO,SAASC,GACdT,KAAKU,YAAYD,GAGjBZ,EAAec,SAAST,EAAU,sBAAuBA,EAAU,yBAAyBU,KAAK,SAASC,GAEpGP,GACFQ,QAAQC,IAAI,wDAAwDF,EAAaR,MAAOE,IAI1EM,EAAaG,YAAcnB,EAAeoB,YAAcJ,EAAaK,QAC3EC,aAAaC,OAAU,eAAgBX,SAAYP,MAE5DmB,MAAM,SAASC,GAEZhB,GACFQ,QAAQC,IAAI,yCAAyCO,EAAKf,MAyBhEG,YAAa,SAASD,GAII,iBAHxBA,EAAWA,SAITA,GAAYc,QAAWd,KAIxB,UAAW,cAAe,SAAU,qBAAsB,gBAAiB,wBAAwBe,QAAQ,SAASC,GAC/GhB,EAASgB,KAAiB7B,IAC5BM,EAAUuB,GAAehB,EAASgB,OAaxCC,MAAO,SAASC,GAEZrB,IADEsB,UAAUC,OAAS,MACLF,MAQrBG,KAAK9B","file":"upup.min.js"} \ No newline at end of file diff --git a/dist/upup.zip b/dist/upup.zip index fd9d941..54480d9 100644 Binary files a/dist/upup.zip and b/dist/upup.zip differ diff --git a/docs/README.md b/docs/README.md index f49f0a0..9d217b3 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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 diff --git a/src/upup.js b/src/upup.js index af28087..8d3ba34 100644 --- a/src/upup.js +++ b/src/upup.js @@ -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 */ @@ -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; @@ -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); @@ -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]; }