【发布时间】:2016-02-02 19:55:32
【问题描述】:
Service Worker 缓存是否支持缓存控制标头?例如,如果缓存中的条目具有标头cache-control: no-store 或cache-control: max-age=60,match() 是否尊重这些标头?
以下代码输出CACHE HIT,尽管响应中出现了标题cache-control: no-store。 (我认为同样的问题也适用于max-age。)
function warm(c) {
var req = new Request("/foo.txt");
var res = new Response("hello", {
status: 200,
statusText: "OK",
headers: new Headers({
"cache-control": "no-store",
"content-type": "text/plain"
})
});
return c.put(req, res).then(function () { return c; });
}
function lookup(c) {
return c.match(new Request("/foo.txt")).then(function (r) {
return r ? "CACHE HIT" : "CACHE MISS";
});
}
function deleteAllCaches() {
return caches.keys().then(function (cacheNames) {
return Promise.all(
cacheNames.map(function (cacheName) {
return caches.delete(cacheName);
})
);
});
}
self.addEventListener('install', function (event) {
event.waitUntil(
deleteAllCaches()
.then(caches.open.bind(caches, 'MYCACHE'))
.then(warm)
.then(lookup)
.then(console.log.bind(console))
.then(function () { return true; })
);
});
【问题讨论】:
标签: javascript cache-control service-worker