Scenario
I use service worker to render shells on the clientside itself this gives me a significant boost in time to first paint. To render the shell I need to create the complete HTML on the client side. The HTML contains links to assets such as CSS and JS. These assets are generated via webpack and have a hash appended to their name. For that I need to make a request inside the service worker to fetch the manifest file. The file looks something like this —
Inside my sw.js, I was making the HTTP request in the beginning of the file. This is an issue because when the service worker starts and if the application is offline this time, the promise returned by the fetch above will simply throw an exception. As of now we will still be getting a 100/100 PWA score because the in the tests, fetch happens only once and the response is saved in the variable manifestJSON and reused for all other tests.
Where as on a mobile device the SW automatically stops after sometime. Visiting the page again in offline mode restarts the SW but this time it isn't able to fetch the manifest file which causes the it to crash.
General Test Case
Register/activate a service worker successfully
Stop the service worker
Go offline
Reload page
Pass Case
200 response is still received
Fail Case
Page Fails to load
Current Case
A false positive is received.
I would be glad to send a PR if someone is accepting :)
Thanks for the detailed report! It's also possible that #709 will address this issue for you though killing the service worker in between passes would be an extra precaution we could take. 👍
We could possibly stop the service worker between the passes. Might as well. If you're interested in contributing this, we could review that PR. It'll be hard though!
Scenario I use service worker to render shells on the clientside itself this gives me a significant boost in time to first paint. To render the shell I need to create the complete HTML on the client side. The HTML contains links to assets such as CSS and JS. These assets are generated via webpack and have a hash appended to their name. For that I need to make a request inside the service worker to fetch the manifest file. The file looks something like this —
Inside my
sw.js
, I was making the HTTP request in the beginning of the file. This is an issue because when the service worker starts and if the application is offline this time, the promise returned by thefetch
above will simply throw an exception. As of now we will still be getting a 100/100 PWA score because the in the tests,fetch
happens only once and the response is saved in the variablemanifestJSON
and reused for all other tests.Where as on a mobile device the SW automatically stops after sometime. Visiting the page again in offline mode restarts the SW but this time it isn't able to fetch the manifest file which causes the it to crash.
General Test Case
Pass Case 200 response is still received
Fail Case Page Fails to load
Current Case A false positive is received.
I would be glad to send a PR if someone is accepting :)