0
3 파일을 캐시해야하지만 다음과 같은 코드가 있습니다. wen 페이지를 다시로드하고 개발자 도구 및 네트워크에 파일을 입력하면 모든 파일이 서비스 담당자에게 전달됩니다. 올바른 코드와 해당 파일 3 개만 있습니다. 캐치되었거나 모든 파일이 잡혀 있습니까?서비스 작업자 캐시
let cache_name = 'v1'
let cache_files = [
'./style/general.css',
'./style/authenticate.css',
'./javascript/app.js'
];
self.addEventListener('install',function(e){
console.log('[ServiceWorker] installed')
e.waitUntil(
caches.open(cache_name).then(function(cache){
console.log('[ServiceWorker] Caching ',cache_files)
return cache.addAll(cache_files)
})
)
});
self.addEventListener('activate',function(e){
console.log('[ServiceWorker] activated')
e.waitUntil(
caches.keys().then(function(cache_names){
return Promise.all(cache_names.map(function(this_cache_name){
if(this_cache_name !== cache_name){
console.log('[ServiceWorker] removing cached files from',this_cache_name)
return caches.delete(this_cache_name)
}
}))
})
)
})
self.addEventListener('fetch',function(e){
e.respondWith(
caches.match(e.request).then(function(response) {
return response || fetch(e.request);
})
);
})
그리고 어떤 파일이 캐시되고 어떤 캐시가 아닌지를 어떻게 알 수 있습니까?
크롬에 lates을 버전이 ? –
@ GeorgianStan 그 이유가 없어야합니다. 사이트는 HTTPS 연결 (일반 HTTP가 아닌)을 통해 제공되어야한다는 것을 기억하십시오. – pate
개발에서 localhost가 대신 할 수 있습니다. https로 작동합니다. 내 컴퓨터에서 범위가 localhost : 3000이기 때문에 범위 문제 일 수 있습니다. 그러나 내 전화와 연결하면 localhost가 아닌 PC의 IP 주소에 연결할 수 있습니다. 충돌 나는 지금 확인합니다. –