【发布时间】: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