This repository has been archived by the owner on May 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(workbox): auto unregister when not enabled (#92)
- Loading branch information
1 parent
965416f
commit 5b45153
Showing
3 changed files
with
49 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { NitroAppPlugin } from 'nitropack' | ||
|
||
export default <NitroAppPlugin> function (nitro) { | ||
nitro.hooks.hook('render:html', (htmlContext) => { | ||
htmlContext.head.push( | ||
[ | ||
'<script>', | ||
'if (\'serviceWorker\' in navigator) {', | ||
' navigator.serviceWorker.getRegistrations().then((registrations) => {', | ||
' for (const registration of registrations) {', | ||
' console.info(\'[PWA] Unregistering Service Worker:\', registration)', | ||
' registration.unregister()', | ||
' }', | ||
' })', | ||
'}', | ||
'if (\'caches\' in window) {', | ||
' caches.keys()', | ||
' .then((keys) => {', | ||
' if (keys.length) {', | ||
' console.info(\'[PWA] Cleaning cache for:\', keys.join(\', \'))', | ||
' for (const key of keys) {', | ||
' caches.delete(key)', | ||
' }', | ||
' }', | ||
' })', | ||
'}', | ||
'</script>', | ||
].join('\n'), | ||
) | ||
}) | ||
} |