Skip to content

Commit

Permalink
Feat: PWA service worker 지정
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtyoon committed Feb 10, 2024
1 parent c3e3b80 commit 7c10248
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/cafevery.svg" />
<link rel="manifest" href="manifest.json" />
<link rel="apple-touch-icon" href="/icon-152x152.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cafevery</title>
<script src="https://maps.googleapis.com/maps/api/js?key=%VITE_GOOGLE_MAPS_API_KEY%&libraries=places"></script>
Expand All @@ -15,5 +16,21 @@
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<script>
if ('serviceWorker' in navigator) {
// Register a service worker hosted at the root of the
// site using the default scope.
navigator.serviceWorker
.register('/PWAServiceWorker.js')
.then((registration) => {
console.log('Service worker registration succeeded:', registration);
})
.catch((err) => {
console.log('Service worker registration failed:', error);
});
} else {
console.log('Service workers are not supported.');
}
</script>
</body>
</html>
13 changes: 13 additions & 0 deletions public/PWAServiceWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
self.addEventListener('install', (e) => {
console.log('[Service Worker] installed');
});

// activate event
self.addEventListener('activate', (e) => {
console.log('[Service Worker] actived', e);
});

// fetch event
self.addEventListener('fetch', (e) => {
console.log('[Service Worker] fetched resource ' + e.request.url);
});

0 comments on commit 7c10248

Please sign in to comment.