service-worker

Open external links in webview as default in IOS PWA

为君一笑 提交于 2019-12-09 17:59:07
问题 I'm testing Progressive Web App in IOS 11.3. My pwa has a Facebook social login button that, when clicked, points to an external link (different windows.location). The problem is that the pwa opens safari app to show external links instead of using a webview within the pwa. So, when the login is done, you will not be redirected to the pwa, but remains in safari. I tried following examples like this one: https://gist.github.com/kylebarrow/1042026 but seems not working How can I force the pwa

Service-Worker, “TypeError:Request failed at <anonymous>”

不想你离开。 提交于 2019-12-09 17:29:52
问题 I hope you can help me with my problem. Currently I build a PWA with a service-worker. It registerd successful, but something is wrong with the installation. The "caches.open"-promise result in an error: "TypeError: Request failed at ". You can see in Chrome, that the cache is registerd, but empty. I already checked the cache urls thousand times.. Here is my Service-worker Code var CACHE_NAME = 'surv-cache-1'; var resourcesToCache = [ '/', '/index.html', '/jquery-3.2.1.min.js', '/pouchdb.min

how to use Service Worker to cache cross domain resources if the response is 404?

本小妞迷上赌 提交于 2019-12-09 16:39:43
问题 w3: 6.2 Cross-Origin Resources and CORS¶ Applications tend to cache items that come from a CDN or other origin. It is possible to request many of them directly using <script>, <img>, <video> and <link> elements. It would be hugely limiting if this sort of runtime collaboration broke when offline. Similarly, it is possible to XHR many sorts of off-origin resources when appropriate CORS headers are set. ServiceWorkers enable this by allowing Caches to fetch and cache off-origin items. Some

Service Worker Response Cache Headers

拈花ヽ惹草 提交于 2019-12-09 16:28:47
问题 I'm trying to figure out how the service worker works in regards to cache headers in responses. I have implemented a couple of service workers now but have never had to bother worrying about caching headers, how long items should be cached for etc. I'm now implementing it on an enterprise production site, whereby this stuff actually really matters. Basically when using a service worker, is the http cache completely bypassed? Do I then need to build a framework to handle resource expiration

Add more service-worker functionality with create-react-app

半腔热情 提交于 2019-12-09 14:42:30
问题 So create-react-app includes service worker functionality by default, which is lovely - all my static assets get cached for offline use out of the box. Cool, but now I want to take things a bit further and use indexedDB to cache some dynamic content. Problem is, there's no service-worker.js file to modify. It gets generated during the build process. Is there a way to add additional logic without ejecting create-react-app or redoing all the nice static caching stuff? 回答1: As you've observed,

An unknown error occurred when fetching the script (Service Worker)

淺唱寂寞╮ 提交于 2019-12-09 14:30:42
问题 When going offline, I get the following error by my service worker: (unknown) #3016 An unknown error occurred when fetching the script my service worker looks like this: var version = 'v1' this.addEventListener('install', function(event){ event.waitUntil( caches.open(version).then(cache => { return cache.addAll([ 'https://fonts.googleapis.com/icon?family=Material+Icons', 'https://fonts.googleapis.com/css?family=Open+Sans:400,600,300', './index.html' ]) }) ) }) this.addEventListener('fetch',

How do I use ServiceWorker without a separate JS file?

十年热恋 提交于 2019-12-08 21:31:57
问题 We create service workers by navigator.serviceWorker.register('sw.js', { scope: '/' }); We can create new Workers without an external file like this, var worker = function() { console.log('worker called'); }; var blob = new Blob( [ '(' , worker.toString() , ')()' ], { type: 'application/javascript' }); var bloburl = URL.createObjectURL( blob ); var w = new Worker(bloburl); With the approach of using blob to create ServiceWorkers, we will get a Security Error as the bloburl would be blob

Service Worker: cache.match(request) returns undefined

China☆狼群 提交于 2019-12-08 20:26:48
问题 I have a simple service worker, that adds two resources (index.html, app.js) to the cache (on install), deletes old caches (on activate) and serves the resources from cache if present, else from the network (on fetch). To get the new service worker registered and to delete old caches I increase the version number in CACHE_NAME with each version of new resources: var CACHE_NAME = 'test-cache-v4'; var urlsToCache = ['./','./app.js']; self.addEventListener('install', function (event) { event

Chrome ServiceWorker postMessage

白昼怎懂夜的黑 提交于 2019-12-08 19:26:04
问题 I try to postMessage between a WebApp and the corresponding ServiceWorker. The serviceWoker is successfully registered and working so far. Unfortunately I noticed some strange behavior: 1. The navigator.serviceWorker.controller is always null. 2. At the serviceWorker side I implemented postMessage this way: self.addEventListener('message', function (evt) { console.log('postMessage received', evt); }); Unfortunately the important field to post back to origin evt.origin=““ and evt.source=null

Long time waiting Request to Service Worker

南楼画角 提交于 2019-12-08 16:04:54
问题 I have noticed that the time waiting for service workers to respond with items from the cache is not as fast as you would expect it to be. I have seen the same wait times with both sw-precache and a custom written service worker. What are the possible causes for this wait time time and how could I reduce it? My fetch event on the custom service worker looks like: self.addEventListener('fetch', function(event) { event.respondWith( caches.match(event.request).then(function(response) { if