【问题标题】:How to remove cache while receiving firefox push notifications如何在接收 Firefox 推送通知时删除缓存
【发布时间】:2016-06-24 13:35:14
【问题描述】:

我的 service-worker.js 中有以下代码行来处理 chrome 和 mozilla 上的传入推送通知:

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' 
                });  

            });  
        }));

    //}));
})

当我更改 latest.json 中的某些内容并发送推送通知时,它仍会从旧的 json 文件加载数据。我如何确保它从更新的 json 中获取数据。为此,我使用了编译指示和缓存控制标头,它在 chrome 中运行良好,但在 Firefox 中不起作用。如何让它在 Firefox 中运行。

【问题讨论】:

    标签: firefox push-notification google-cloud-messaging mozilla service-worker


    【解决方案1】:

    您可以将cache 参数用于fetch 调用。

    例如,通过将其设置为no-store,您可以完全绕过缓存。

    阅读specification of the Fetch APIcache mode的描述了解更多详情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-28
      • 1970-01-01
      • 2017-12-22
      • 2015-11-14
      • 1970-01-01
      • 1970-01-01
      • 2019-04-23
      • 1970-01-01
      相关资源
      最近更新 更多