Cache
This commit is contained in:
		
							parent
							
								
									9a9124c6ea
								
							
						
					
					
						commit
						c79aa36c63
					
				
					 1 changed files with 31 additions and 1 deletions
				
			
		| 
						 | 
					@ -4,9 +4,39 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import composeNotification from './common/scripts/compose-notification';
 | 
					import composeNotification from './common/scripts/compose-notification';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// キャッシュするリソース
 | 
				
			||||||
 | 
					const cachee = [
 | 
				
			||||||
 | 
						'/'
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// インストールされたとき
 | 
					// インストールされたとき
 | 
				
			||||||
self.addEventListener('install', () => {
 | 
					self.addEventListener('install', ev => {
 | 
				
			||||||
	console.info('installed');
 | 
						console.info('installed');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Cache
 | 
				
			||||||
 | 
						ev.waitUntil(caches.open(_VERSION_).then(cache => cache.addAll(cachee)));
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// アクティベートされたとき
 | 
				
			||||||
 | 
					self.addEventListener('activate', ev => {
 | 
				
			||||||
 | 
						// Clean up old caches
 | 
				
			||||||
 | 
						ev.waitUntil(
 | 
				
			||||||
 | 
							caches.keys().then(keys => Promise.all(
 | 
				
			||||||
 | 
								keys
 | 
				
			||||||
 | 
									.filter(key => key != _VERSION_)
 | 
				
			||||||
 | 
									.map(key => caches.delete(key))
 | 
				
			||||||
 | 
							))
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// リクエストが発生したとき
 | 
				
			||||||
 | 
					self.addEventListener('fetch', ev => {
 | 
				
			||||||
 | 
						ev.respondWith(
 | 
				
			||||||
 | 
							// キャッシュがあるか確認してあればそれを返す
 | 
				
			||||||
 | 
							caches.match(ev.request).then(response =>
 | 
				
			||||||
 | 
								response || fetch(ev.request)
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// プッシュ通知を受け取ったとき
 | 
					// プッシュ通知を受け取ったとき
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue