service-worker

ServiceWorkerContainer.ready for a specific scriptURL?

萝らか妹 提交于 2019-12-02 02:44:56
问题 ServiceWorkerContainer.ready resolves to an active ServiceWorkerRegistration, but if there are multiple service workers in play (e.g. service workers from previous page loads, multiple registrations within the same page) there are multiple service workers it could resolve to. How can I make sure that a particular service worker is handling network events when a chunk of code is executed? That is, how can I write a function registerReady(scriptURL, options) that can be used as follows:

Service worker - network first then cache with fallback to static page

泪湿孤枕 提交于 2019-12-01 21:11:30
I want to add service worker to my site to offer a good offline experience to my site users. (Site back-end is PHP) I'm still new to Javascript promises and service workers, but here is what i reached so far : my index.php page has this script to register service worker <script> if ('serviceWorker' in navigator) { navigator.serviceWorker.register('sw.js')}; </script> and for service worker file i use the following code var CACHE_STATIC_NAME = 'static-v74'; var CACHE_DYNAMIC_NAME = 'dynamic-v74'; self.addEventListener('install', function (event) { console.log('Installing Service Worker ...',

Service worker - network first then cache with fallback to static page

故事扮演 提交于 2019-12-01 20:38:19
问题 I want to add service worker to my site to offer a good offline experience to my site users. (Site back-end is PHP) I'm still new to Javascript promises and service workers, but here is what i reached so far : my index.php page has this script to register service worker <script> if ('serviceWorker' in navigator) { navigator.serviceWorker.register('sw.js')}; </script> and for service worker file i use the following code var CACHE_STATIC_NAME = 'static-v74'; var CACHE_DYNAMIC_NAME = 'dynamic

DOMException when registering service worker inside an https iframe

时间秒杀一切 提交于 2019-12-01 20:11:46
问题 I'm trying to register a service worker in an https iframe inside an http (unsecured) site. Until lately, my code ran without any issues. From the last chrome update (44) this code fails inside the iframe: navigator.serviceWorker.register('./service-worker.js'); I get this error in console: Uncaught (in promise) DOMException: Only secure origins are allowed Was there any change that now prevents secured iframes from registering service workers if they are running in an unsecured parent? 回答1:

How to cache bust sw-toolbox?

不打扰是莪最后的温柔 提交于 2019-12-01 18:47:36
问题 I have been toying around with service workers and sw-toolbox. Both are great methods but seems to have their weaknesses. My project started out using Google's method of service workers (link). The way I see this is that you have to manually update the version number for cache busting. I could be wrong also but I don't think the pages that the users has visited will not be cached. Compared to the sw-toolbox method, all I need to add is the following code: self.toolbox.router.default = self

How to cache bust sw-toolbox?

谁说胖子不能爱 提交于 2019-12-01 18:13:06
I have been toying around with service workers and sw-toolbox. Both are great methods but seems to have their weaknesses. My project started out using Google's method of service workers ( link ). The way I see this is that you have to manually update the version number for cache busting. I could be wrong also but I don't think the pages that the users has visited will not be cached. Compared to the sw-toolbox method, all I need to add is the following code: self.toolbox.router.default = self.toolbox.networkFirst; self.toolbox.router.get('/(.*)', function (req, vals, opts) { return self.toolbox

DOMException when registering service worker inside an https iframe

可紊 提交于 2019-12-01 18:05:32
I'm trying to register a service worker in an https iframe inside an http (unsecured) site. Until lately, my code ran without any issues. From the last chrome update (44) this code fails inside the iframe: navigator.serviceWorker.register('./service-worker.js'); I get this error in console: Uncaught (in promise) DOMException: Only secure origins are allowed Was there any change that now prevents secured iframes from registering service workers if they are running in an unsecured parent? It appears that this did change recently . It also appears that the current behaviour will now be maintained

Why does Chrome keep displaying “Site cannot be installed: the page is not served from a secure origin” in the console?

谁说我不能喝 提交于 2019-12-01 17:39:11
Whenever I look in Chrome's console, I see this error message: Site cannot be installed: the page is not served from a secure origin This only started happening a few days ago, and Chrome wasn't updated in the meantime. This error is caused by sites served over HTTP if "Add to shelf" is enabled in chrome://flags. Solutiuon: go to chrome://flags/#enable-add-to-shelf and change "Enabled" to "Default", then relaunch chrome. 来源: https://stackoverflow.com/questions/41863050/why-does-chrome-keep-displaying-site-cannot-be-installed-the-page-is-not-serve

Access localStorage from service worker

百般思念 提交于 2019-12-01 17:36:18
I want to periodically call an API from my service worker to send data stored in the localStorage. This data will be produced and saved in localStorage when a user browses my website. Consider it something like saving stats in localStorage and sending it periodically through the service worker. How should I do this? I understand that I can't access localStorage from service worker and will have to use the postMessage API. Any help would be highly appreciated. GibboK You cannot access localStorage (and also sessionStorage) from a webworker process, they result will be undefined , this is for

Access localStorage from service worker

浪尽此生 提交于 2019-12-01 15:47:34
问题 I want to periodically call an API from my service worker to send data stored in the localStorage. This data will be produced and saved in localStorage when a user browses my website. Consider it something like saving stats in localStorage and sending it periodically through the service worker. How should I do this? I understand that I can't access localStorage from service worker and will have to use the postMessage API. Any help would be highly appreciated. 回答1: You cannot access