質問編集履歴

1

ソースを追加

2020/09/16 05:25

投稿

otftrough
otftrough

スコア476

test CHANGED
File without changes
test CHANGED
@@ -15,3 +15,135 @@
15
15
 
16
16
 
17
17
  なにか特殊な方法が必要でしょうか?
18
+
19
+
20
+
21
+
22
+
23
+ ---
24
+
25
+ **追記**
26
+
27
+
28
+
29
+ index.htmlでのServiceWorkerの登録は下記のようになっています。
30
+
31
+ ```JacaScript
32
+
33
+
34
+
35
+ if ('serviceWorker' in navigator) {
36
+
37
+ navigator.serviceWorker.register('sw.js')
38
+
39
+ .then(reg => {
40
+
41
+ console.log('Service worker registered.', reg);
42
+
43
+ reg.onupdatefound = () => {
44
+
45
+ console.log('cash update.');
46
+
47
+ reg.update();
48
+
49
+ }
50
+
51
+ if (typeof reg.update == 'function') {
52
+
53
+ console.log('cash update.');
54
+
55
+ reg.update();
56
+
57
+ }
58
+
59
+ });
60
+
61
+ } else console.log('Service worker can\'t registered.');
62
+
63
+ ```
64
+
65
+
66
+
67
+ sw.jsの中身です。
68
+
69
+ ```JacaScript
70
+
71
+ var CACHE_NAME = "otft-info-20200914";
72
+
73
+ var urlsToCache = [
74
+
75
+ "/",
76
+
77
+ "index.html",
78
+
79
+ "info/otftnamelogo.png",
80
+
81
+ "info/note.svg",
82
+
83
+ "info/beat01.png",
84
+
85
+ "info/LogIcon.png"
86
+
87
+ ];
88
+
89
+
90
+
91
+ self.addEventListener('install', function(event) {
92
+
93
+ event.waitUntil(
94
+
95
+ caches
96
+
97
+ .open(CACHE_NAME)
98
+
99
+ .then(function(cache){
100
+
101
+ return cache.addAll(urlsToCache);
102
+
103
+ })
104
+
105
+ );
106
+
107
+ });
108
+
109
+
110
+
111
+ self.addEventListener('fetch', function(e) {
112
+
113
+ });
114
+
115
+
116
+
117
+ self.addEventListener('activate', function(event) {
118
+
119
+ event.waitUntil(
120
+
121
+ caches.keys().then(function(cacheNames) {
122
+
123
+ return Promise.all(
124
+
125
+ cacheNames.filter(function(cacheName) {
126
+
127
+ return cacheName !== CACHE_NAME;
128
+
129
+ }).map(function(cacheName) {
130
+
131
+ console.info("delete cache: " + cacheName);
132
+
133
+ return caches.delete(cacheName);
134
+
135
+ })
136
+
137
+ );
138
+
139
+ }).then(() => {
140
+
141
+ clients.Claim();
142
+
143
+ })
144
+
145
+ );
146
+
147
+ });
148
+
149
+ ```