1

파이어 폭스 푸시 알림을 수신하는 동안 캐시를 제거하는 방법 :내가 크롬과 모질라에 들어오는 푸시 알림을 처리하기 위해 내 서비스 worker.js 코드의 라인을 다음 한

var httpHeaders = new Headers(); 
    httpHeaders.append('pragma', 'no-cache'); 
    httpHeaders.append('cache-control', 'no-cache'); 

var fetchInit = { 
    method: 'GET', 
    headers: httpHeaders, 
}; 

// Version 0.1 
console.log('Started', self); 
self.addEventListener('install', function(event) { 
    self.skipWaiting(); 
    console.log('Installed', event); 
}); 
self.addEventListener('activate', function(event) { 
    console.log('Activated', event); 
}); 
var urlToRedirect=''; 
self.addEventListener('push', function(event) { 
    console.log('Push message', event); 
    //var title = 'Push message2'; 
    event.waitUntil(

    fetch("http://abc/xyz/latest.json", fetchInit).then(function(res) { 
     res.json().then(function(data) { 
     // Show notification 
       urlToRedirect = data.data.url; 
       self.registration.showNotification(data.data.title, { 
        body: data.data.body, 
        tag: data.data.tag, 
        icon: 'images/icon.png' 
       }); 

      }); 
     })); 

    //})); 
}) 

내가 최근에 뭔가를 변경합니다. json으로 보내고 푸시 알림을 보내면 이전 json 파일에서 데이터를로드합니다. 업데이트 된 json에서 데이터를 가져 오는 방법은 무엇입니까? 이를 위해, 나는 pragma와 cache-control 헤더를 사용했고, 크롬에서는 잘 작동하지만 파이어 폭스에서는 작동하지 않는다. Firefox에서 작동시키는 법.

답변

1

fetch 호출에 cache 매개 변수를 사용할 수 있습니다.

예를 들어 no-store으로 설정하면 캐시를 완전히 무시할 수 있습니다.

자세한 내용은 specification of the Fetch APIcache mode에 대한 설명을 참조하십시오.