Skip to content

Commit 29d97ce

Browse files
committed
add PWA Examples
1 parent 8ef67ef commit 29d97ce

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

pwa/index.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<meta charset="UTF-8" />
4+
<title>Hello World</title>
5+
<link rel="stylesheet" href="test.css" />
6+
</head>
7+
<body>
8+
<header>
9+
TEST HEADER
10+
</header>
11+
<div id="main"></div>
12+
<script src="test.js"></script>
13+
<script>
14+
if ('serviceWorker' in navigator) {
15+
window.addEventListener('load', function() {
16+
navigator.serviceWorker.register('./registerServiceWorker.js').then(function(registration) {
17+
console.log("서비스 워커 등록 완료", registration.scope);
18+
}).catch(function(err) {
19+
console.log("서비스 워커 등록 실패", err);
20+
})
21+
})
22+
}
23+
</script>
24+
</body>
25+
</html>

pwa/registerServiceWorker.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const CACHE_NAME = "test-cashe-1";
2+
3+
const urlsToCache = [
4+
'/pwa/',
5+
'/pwa/test.css',
6+
'/pwa/test.js'
7+
]
8+
9+
self.addEventListener('install', function(event) {
10+
event.waitUntil(
11+
caches.open(CHCHE_NAME)
12+
.then(function(cache) {
13+
console.log("CACHE 등록 완료");
14+
return cache.addAll(urlsToCache);
15+
})
16+
);
17+
})

pwa/test.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#main::after {
2+
content: "CSS is ON";
3+
display: block;
4+
color: white;
5+
}

pwa/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const main = document.querySelector("#main");
2+
3+
main.innerHTML = "이것이 보인다면 스크립트가 정상적으로 로딩된 것입니다";

0 commit comments

Comments
 (0)