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

Negation in navigateFallbackWhitelist #292

Closed SvenSeemann closed 7 years ago

SvenSeemann commented 7 years ago

Hello everyone, i'm trying to use sw-precache on my project, but im currently struggling with the navigateFallback and navigateFallbackWhitelist.

For my static assets everything works fine, but I have a resource wich is used to download files, which should not be served by the service worker.

So I have paths like /.js, /.css, etc., wich should be cached, but everything behind /attachments/someID/download shouldn't. In my understanding I would need more something like navigateFallbackBlacklist (as negation is not supported anymore by glob).

jeffposnick commented 7 years ago

Yeah, blacklisting vs. whitelisting is a sticky issue.

The values that you pass in are RegExp objects, not glob patterns, so it's not too bad to negate it:

{
  navigateFallbackWhitelist: [/^(?!.*attachments)/],
  // other options
}

(In the currently WIP successor to this library, we'll support both white and blacklists.)