GoogleChromeLabs / sw-precache

[Deprecated] A node module to generate service worker code that will precache specific resources so they work offline.
https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-sw
Apache License 2.0
5.22k stars 388 forks source link

Custom handler in runtimeCaching #299

Closed jegj closed 7 years ago

jegj commented 7 years ago

I would like to implement my own logic on a custom handler on the runtimeCaching option. Intercept an ajax request and respond using data on IndexDB or send the request to the network and update my indexDB data. is that posible?

jeffposnick commented 7 years ago

It's probably easiest to implement that logic inside your own standalone script, and then pass the path to that script in to the importScripts option when you build your service worker.

Alternatively, you can explore using the new Workbox project, which uses a model in which it's easier for you to add code to your top-level service worker file, including putting in custom runtime routing logic: https://workboxjs.org/examples/workbox-sw/