服务工作者和AppCache之间的核心区别是什么.每个人的优缺点是什么,何时优先选择另一个人.
我serviceworker具有逻辑,当获取事件发生,首先它取其中包含一些布尔值(不是event.request.url)端点和检查值的基础上,我打电话值event.respondWith()为当前获取事件,我从缓存中提供响应.但是我收到以下错误,
未捕获(在promise中)DOMException:无法在'FetchEvent'上执行'respondWith':fetch事件已被响应
我在这里检查了当m_state不等于Initial时抛出此错误
if (m_state != Initial) {
exceptionState.throwDOMException(InvalidStateError, "The fetch event has already been responded to.");
return;
}
Run Code Online (Sandbox Code Playgroud)
我怀疑,因为我有一个额外的获取事件,它以某种方式消耗了前一个fetch事件,它正在改变m_state变量,虽然我没有获取事件url.I我不知道是什么原因,什么是它的解决方案.但它为什么这么说
我正在粘贴下面的代码片段.
function fetchEvt(event) {
check().then(function (status) {
if (status === 0) {
handleRequest(event);
}
});
}
function checkHash() {
return new Promise(function (resolve) {
fetch(endpoint, { credentials: 'include' }).then(function (response) {
return response.text();
}).then(function (text) {
resolve(text);
});
}
}
function handleRequest(event) {
event.respondWith(caches.match(event.request.url).then(function (Response) {
if (Response) {
return …Run Code Online (Sandbox Code Playgroud) 据我所知,服务工作者无法访问cookie.因此,我在为我的网站实施SW时面临很多问题.
我想知道是什么原因,服务工作者无法访问cookie.现在我正在使用消息传递将cookie内容传达给服务工作者.有没有更好的方法或黑客更有效地做到这一点?
我希望我的服务人员获得屏幕的高度和宽度。
我试过 screen.height、self.innerHeight、window.innerHeight,但似乎服务工作者在不同的上下文中运行,这些上下文未定义。
有没有办法在 service worker 的上下文中访问设备信息,比如高度和宽度?