Open WayneHiller opened 5 years ago
right, that should be a regex. pr is welcome.
it's line 44 we convert those strings to regexps.
since runtimeCaching
is an array, you may need to loop deeper.
https://github.com/cyyyu/parcel-plugin-sw-precache/blob/master/index.js#L44
Actually I did a bunch of digging through the docs and it seems a string should work as well.
From sw-precache docs: Each Object in the Array needs a urlPattern, which is either a RegExp or a string, following the conventions of the sw-toolbox library's routing configuration.
And then from the sw-toolbox docs: toolbox.router.<get|post|put|delete|head>(urlPattern, handler, options) Create a route that causes requests for URLs matching urlPattern to be resolved by calling handler. Matches requests using the GET, POST, PUT, DELETE or HEAD HTTP methods respectively.
urlPattern - an Express style route. See the docs for the path-to-regexp module for the full syntax
It seems they use https://github.com/pillarjs/path-to-regexp under the hood.
In my case it was actually better to just set navigateFallback to blank:
"sw-precache": {
"maximumFileSizeToCacheInBytes": 10485760,
"navigateFallback": ""
}
It would probably make more sense to just use a regexp instead of those Express style paths.
Nice investigation. I personally prefer Express style pattern but I would say they are very similar and both easily defined in most cases. Feel free to file a pr if you still want regexp support in this plugin.
I was reading through the sw-precache to workbox conversion notes at https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-sw and it states:
Deprecated options Express-style wildcard routes are no longer supported. If you were using Express-style wildcard routes in either the runtimeCaching configuration or directly in sw-toolbox, please migrate to an equivalent regular expression route when using Workbox.
So maybe it would be best to change it to use a RegExp.
Any news on this? I need to do the same but I don't quite understand how I need to write the urlPattern for this to work...
@nickimola As said you could use Express-style wildcard routes which are presented in strings rather than regular expressions. Check out the doc of sw-precache. Express-style wildcard routes is deprecated in sw-toolbox but this plugin actually relies on sw-precache. And don't worry about backward compatibility for now as I will bump a major version if we eventually migrate to sw-toolbox.
I want some URLs to always be supplied from the server. Am I doing this correctly? Not sure if the /.../ will be supplied as a regex?
This is at the end of the serviceworker.js file. Should that be a string or regex?