Skip to content

Commit

Permalink
fix: Root as default service-worker url (#9)
Browse files Browse the repository at this point in the history
* fix: Root as default service-worker url

* fix
  • Loading branch information
mircostraessle authored Feb 26, 2021
1 parent 904cb7f commit 38c5abf
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/hooks/use-service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ let workbox: Workbox | null = null;
let updateCallback: () => void = () => window.location.reload();

type Props = {
/** Url to the service-worker script (Default: '/service-worker.js') */
scriptUrl?: string;
/** Intervall in ms after which an update check for a new service worker on the server is enforced */
periodicUpdateInterval?: number;
};

Expand All @@ -17,7 +19,7 @@ export const useServiceWorker = (props?: Props): [boolean, () => void | null] =>

// Inspired by https://developers.google.com/web/tools/workbox/guides/advanced-recipes#offer_a_page_reload_for_users
if ('serviceWorker' in navigator && process.env.NODE_ENV !== 'development') {
workbox = new Workbox(props?.scriptUrl || 'service-worker.js');
workbox = new Workbox(props?.scriptUrl ?? '/service-worker.js');
let registration: ServiceWorkerRegistration | undefined;

updateCallback = () => {
Expand Down

0 comments on commit 38c5abf

Please sign in to comment.