Use a single fetch handler for all Router instances
See original GitHub issueLibrary Affected: 5.0.0 workbox-google-analytics, workbox-routing, etc.
Browser & Platform: “all browsers”
Issue or Feature Request Description:
I’m using setDefaultHandler with offline-fallback page “sw-offline” to handle non-matching requests along with offline googleAnalytics.
However, the fetch routes added by googleAnalytics is not preferred over setDefaultHandler. For all “google analytics” requests, default route set by setDefaultHandler is used.
// few registerRoute are used here
workbox.googleAnalytics.initialize();
const defaultNetworkOnlyHandler = async (args) => {
console.log('Default:'+args.url);
try {
var defaultNetworkOnly = new NetworkOnly({
fetchOptions: args.event.request.mode=='navigate'?{}:{credentials:'include'}
});
const response = await defaultNetworkOnly.handle(args);
return response || await caches.match('sw-offline');
} catch(error) {
return await caches.match('sw-offline');
}
};
setDefaultHandler(defaultNetworkOnlyHandler);
As it can be seen in console, “https://www.google-analytics.com/analytics.js” always uses default route of “NetworkOnly” instead of “NetworkFirst” route defined in workbox-google-analytics. Due to which analytics.js is not cached and throws an error in offline mode.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
express.js - single routing handler for multiple routes in a ...
I came across this question while looking for the same functionality. @Jonathan Ong mentioned in a comment above that using arrays for paths...
Read more >workbox-routing - Chrome Developers
Routes requests in your service worker to specific caching strategies or callback functions.
Read more >FetchEvent - Web APIs | MDN
Chrome Edge
FetchEvent Full support. Chrome40. Toggle history Full support. Edge17. Tog...
FetchEvent() constructor Full support. Chrome40. Toggle history Full support. Edge17. Tog...
clientId Full support....
Read more >Using Express.js Routes for Promise-based Error Handling
status(200).send(data); // routes/users.js router.get('/', function(req, ...
Read more >Easier Service Worker caching with Routing - ITNEXT
One, it uses a middleware pattern so you can chain handlers. ... you can use a default route at the end to handle...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Actually, I forgot that
workbox-precaching
in v6 creates it ownRouter
instead of using the defaultRouter
, so forget what I said about it being similar.@jeffposnick ok, thanks!