2

I have a quick question.

I'm building a PWA with Polymer and Lighthouse reports, that the manifest's start_url is not cached by the ServiceWorker.

Since I want to track the users, which use the 'Add to homescreen' function, my manifest.json contains

"start_url": "index.html?homescreen=1",

I tried putting this exact string into my sw-precache config file, but the script generates a ServiceWorker, that just caches the index.html file. (I'm aware, that it's a bit redundant to cache index.html & index.html?homescreen=1)

Do you have any idea, how to fix this behaviour?

Thanks!

Nicolai Schmid
  • 1,022
  • 1
  • 14
  • 29

1 Answers1

3

The ignoreUrlParametersMatching option is sw-precache can help you here.

By default, it's set to [/^utm_/], meaning that if you configured your Web App Manifest like

{
  "start_url": "index.html?utm_source=homescreen"
}

then things should work as expected. If you'd like to keep that ?homescreen=1, then, when generating your service worker, you can change explicitly set the ignoreUrlParametersMatching parameter to [/^homescreen/].

Jeff Posnick
  • 53,580
  • 14
  • 141
  • 167
  • That was a very good answer! Do you have an idea, how to cache routes, like `start_url: '/about?utm_source=homescreen` which would resolve in a view file located at `/src/views/about-view.html` ? – Nicolai Schmid Jun 10 '17 at 11:16
  • No, I'm not sure about that. – Jeff Posnick Jun 10 '17 at 12:22
  • Is it possible to add such rule to an app created with [create-react-app](https://github.com/facebookincubator/create-react-app) boilerplate without eject? – piotr_cz Jun 23 '17 at 07:39
  • c-r-a uses `sw-precache` under the hood, and it will automatically precache any local HTML files at build time. So if you have a local about.html file, that will work as expected without ejecting. – Jeff Posnick Jun 23 '17 at 14:03