0
매우 간단합니다. 나는 콘텐츠가 변경 가능하기 때문에 네트워크 우선 캐싱을 시도하고있다. 그러나 서비스 담당자는 네트워크 대신 디스크 캐시에서 서비스를 제공하는 것으로 보입니다. Chromium에서 서버의 업데이트 여부를 확인하는 것조차 보이지 않습니다. 첨부 된 스크린 샷보기서비스 작업자 가져 오기가 네트워크 요청을하지 못합니다.
<html>
<body>
<script>
function printFile() {
fetch('file.txt').then(resp => resp.text()).then(x => console.log(x));
}
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js')
.then(function(reg) {
// registration worked
console.log('Registration succeeded. Scope is ' + reg.scope);
navigator.serviceWorker.ready.then(printFile);
}).catch(function(error) {
// registration failed
console.log('Registration failed with ' + error);
});
}
</script>
</body>
</html>
및 서비스 노동자 :
self.addEventListener('install', function(event) {
event.waitUntil(self.skipWaiting());
});
self.addEventListener('activate', function(event) {
event.waitUntil(self.clients.claim());
});
self.addEventListener('fetch', function(event) {
console.log('Fetching ' + event.request.url);
event.respondWith(
fetch(event.request)
);
});
가 어떻게 file.txt
의 새로운 복사본을 가져 오기 위해 서버에 요청을 만들기 위해 내 서비스 노동자를 강제 할 수 여기에