ipfs-shipyard / ipfs-service-worker-demos

[INACTIVE/DEPRECATED] Demo ~2017: run an IPFS node inside a Service Worker and serve all your IPFS URLs directly from IPFS!
MIT License
84 stars 15 forks source link

Understand why the page requires to be refreshed one time in order for the Service Worker to kick in #4

Closed daviddias closed 8 months ago

daviddias commented 7 years ago

@frankiebee can you show me the piece in Mascara that solves this issue?

claus commented 7 years ago

I believe this is a service worker feature, not a bug.

See https://developers.google.com/web/fundamentals/instant-and-offline/service-worker/lifecycle#the_first_service_worker (particularly the Activate and clients.claim sections)

The default is consistency, if your page loads without a service worker, neither will its subresources. If you load the demo a second time (in other words, refresh the page), it'll be controlled

frankiebee commented 7 years ago

Oh hello @diasdavid sorry for the late response but yes we use clients.claim in a event listener on the activate event https://github.com/MetaMask/metamask-extension/blob/master/mascara/src/background.js#L35

how ever we also reload the "ui" if we find we haven't made a connection with the sw but the sw is active https://github.com/MetaMask/metamask-extension/blob/master/mascara/src/ui.js#L49L55 (this might be unnecessary for what your doing)