service-worker

Using Webworkers in angular app (service worker cache access of data in angular-cli)

泄露秘密 提交于 2019-11-30 03:14:03
问题 I wish to run an function (in the background) using a worker. The data comes from a http request. I am using a mock calculation (e.data[0] * e.data[1] * xhrData.arr[3]) (replaced by a function returning the actual algo result) as below: var ajax = function() { var prom = new Promise(function(resolve, reject){ if (!!XMLHttpRequest) { var xhttp = new XMLHttpRequest(); xhttp.onload = function () { if (this.readyState == 4 && this.status == 200) { resolve(JSON.parse(this.responseText)); } }; //

add to home screen not showing up PWA

£可爱£侵袭症+ 提交于 2019-11-30 02:40:36
问题 I've created a Progressive Web App. It's simple, just an index.html, a folder "images" with favicon etc, a sw.js et a styles.css My code from manifest.json { "lang" : "en", "name" : "Test", "short_name" : "Test", "icons" : [ { "src": "images/android-chrome-192x192.png", "sizes": "192x192", "type": "image/png" }, { "src": "images/android-chrome-144x144.png", "sizes": "144x144", "type": "image/png" } ], "theme_color" : "#116b20", "background_color" : "#1a1a1a", "scope" : "1", "start_url" : "

Application Cache or Service Workers - which to use in 2016/Q2?

北城余情 提交于 2019-11-30 00:01:48
Quick question for discussion really, as I wanted to have input from different people. I am in the process of developing a web page app that must be available offline. Now to do this, as I understand it, you would go about using either the application caching feature or by using service workers. However, here is the conundrum I have. When researching the application cache, the MDN clearly states : Deprecated: This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web

Use ServiceWorker cache only when offline

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 23:49:41
I'm trying to integrate service workers into my app, but I've found the service worker tries to retrieve cached content even when online, but I want it to prefer the network in these situations. How can I do this? Below is the code I have now, but I don't believe it is working. SW Install code is omitted for brevity. var CACHE_NAME = 'my-cache-v1'; var urlsToCache = [ /* my cached file list */ ]; self.addEventListener('install', function(event) { // Perform install steps event.waitUntil( caches.open(CACHE_NAME) .then(function(cache) { console.log('Opened cache'); return cache.addAll

Service-worker force update of new assets

。_饼干妹妹 提交于 2019-11-29 22:53:35
I've been reading through the html5rocks Introduction to service worker article and have created a basic service worker that caches the page, JS and CSS which works as expected: var CACHE_NAME = 'my-site-cache-v1'; var urlsToCache = [ '/' ]; // Set the callback for the install step self.addEventListener('install', function (event) { // Perform install steps event.waitUntil( caches.open(CACHE_NAME) .then(function(cache) { console.log('Opened cache'); return cache.addAll(urlsToCache); }) ); }); self.addEventListener('fetch', function (event) { event.respondWith( caches.match(event.request) .then

Service worker: Fetch event listener only works after page reload

你。 提交于 2019-11-29 22:14:45
问题 I have added a service worker to my page with the code below. It works well once the page has been reloaded and the worker already installed. But does not seem to catch any fetch events before the page is reloaded after I have seen the 'SW INSTALL' log. app.js navigator.serviceWorker.register('/worker.js').then((registration) => { console.log('ServiceWorker registration successful with scope: ', registration.scope); }, (err) => { console.log('ServiceWorker registration failed: ', err); });

Using service workers across multiple subdomains

家住魔仙堡 提交于 2019-11-29 18:34:22
问题 If my web app consists of more than one subdomain, does that mean I have to have multiple service workers, one for each subdomain? Or can I have one service worker that works across subdomains? 回答1: Each subdomain is considered a different origin, so yes, you will need to register a service worker for each one. Each of these workers will have its own cache and scope. 回答2: Each subdomain is considered a different origin and you must register a service worker for each origin but you can reuse

URL of page currently being served by Service Worker 'fetch' event

陌路散爱 提交于 2019-11-29 16:04:31
How can I get the full URL of the page which is being serviced by a service worker's 'fetch' event? The "self.location" property seems to only refer to the root URL of the site. For example, if page https://example.com/folder/pagename.html is performing a fetch which the service worker is intercepting, the service worker's 'self.location' property returns " https://example.com ". event.currentTarget.location and event.explicitOriginalTarget.location, event.originalTarget, and event.target all return the URL of the service worker .js file. How can I get the full URL of the page that triggered

How to register a service worker's scope one directory above where the service_worker.js is located

心不动则不痛 提交于 2019-11-29 13:27:12
MY directories are as follows. public_html/ sw/ The "sw/" is where I want to put all service workers, but then have those service workers with a scope to all the files in "public_html/". JS <script> if ('serviceWorker' in navigator) { navigator.serviceWorker.register('sw/notifications.js', { scope: '../sw/' }).then(function(reg) { // registration worked console.log('Registration succeeded. Scope is ' + reg.scope); }).catch(function(error) { // registration failed console.log('Registration failed with ' + error); }); }; </script> How do I allow this sort of scope? The max scope for a service

Service Worker Registration Failed

痞子三分冷 提交于 2019-11-29 13:26:20
I am currently working on service worker to handle push notification in browser. Currently I am having this "SW registration failed error". Can anyone help with this issue? Check client1.html and service-worker.js file below: ERROR: SW registration failed with error SecurityError: Failed to register a ServiceWorker: The URL protocol of the current origin ('null') is not supported. service-worker.js console.log('Started', self); self.addEventListener('install', function(event) { self.skipWaiting(); console.log('Installed', event); }); self.addEventListener('activate', function(event) { console