Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add service worker and make PWA installable #165

Merged
merged 3 commits into from
Jul 15, 2023

Conversation

ZauberNerd
Copy link
Contributor

This commit adds a service worker to make the app installable as a PWA. In addition to caching all generated build artifacts (css and js filse) the service worker also caches all other static files via a stale-while-revalidate strategy (png, ico, json, css from the public folder).
Further, this commit adds a Notification which will be shown when the service worker updates and clicking on the button inside it causes the service worker to update and the page to reload.

In order to make a PWA installable we need to follow some guide lines: https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Guides/Making_PWAs_installable

Fixes: #147

This commit adds a service worker to make the app installable as a PWA.
In addition to caching all generated build artifacts (css and js filse)
the service worker also caches all other static files via a
stale-while-revalidate strategy (png, ico, json, css from the public
folder).
Further, this commit adds a Notification which will be shown when the
service worker updates and clicking on the button inside it causes
the service worker to update and the page to reload.

In order to make a PWA installable we need to follow some guide lines:
https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Guides/Making_PWAs_installable

Fixes: cogentapps#147
@cogentapps
Copy link
Owner

Thanks for working on this!

In my tests, it looks like the build isn't outputting /service-worker.js in the right place. I'll dig into it a bit more and try to see what the best fix is.

@ZauberNerd
Copy link
Contributor Author

@cogentapps ah yes, this implementation relied on the workbox integration of create-react-app, so now we need to change it to vite. I found a vite-plugin-pwa and could refactor this PR for it.

@cogentapps cogentapps merged commit c75663b into cogentapps:main Jul 15, 2023
@ZauberNerd ZauberNerd deleted the service-worker branch July 16, 2023 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Progressive Web App
2 participants