Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

runtimeCaching not working? #149

Closed
portokallidis opened this issue Aug 2, 2016 · 1 comment
Closed

runtimeCaching not working? #149

portokallidis opened this issue Aug 2, 2016 · 1 comment

Comments

@portokallidis
Copy link

portokallidis commented Aug 2, 2016

Hello,

Sorry this probably is not a bug but my head is going to explode.

I have this app: https://edu.carre-project.eu/ and a service worker file in https://edu.carre-project.eu/service-worker.js generated by this conf :

{
  "staticFileGlobs": [
    "dist/public/app/*",
    "dist/public/manifest_icons/*",
    "dist/public/fonts/*",
    "dist/public/*"
  ],
  "stripPrefix": "dist/public/",
  "runtimeCaching": [{
    "urlPattern": "/^https:\/\/edu\\.carre-project\\.eu\/api\/",
    "handler": "networkFirst"
  }]
}


from the cli command : sw-precache --config=sw-precache-config.json
My main problem is that it doesnt cache the api...
I have also tried this regex /(.*)\/api\/(.*)/ and single request such as 'api/config.json' but again with no luck 
Is there any obvious mistake in my conf?
@jeffposnick
Copy link
Contributor

I just gave it a try, and that generates toolbox.router.get(/^https://edu\.carre-project\.eu/api/, toolbox.networkFirst, {});, which is an invalid RegExp.

String escaping in JSON is coming into play here, and you need to actually escape all the '' characters in the string, so that they make it into the final RegExp. (You're only double-escaping some of them.)

Try "urlPattern": "/^https:\\/\\/edu\\.carre-project\\.eu\\/api\\//", which leads to toolbox.router.get(/^https:\/\/edu\.carre-project\.eu\/api\//, toolbox.networkFirst, {}); in the output.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants