Mar*_*ner 4 javascript offline offline-browsing service-worker
我的网站注册了一个 ServiceWorker,其范围仅限于以/sw/....
/**\n * Register the Service Worker.\n */\n if (\'serviceWorker\' in navigator) {\n navigator.serviceWorker\n .register(\'{{ URL::asset(\'sw/serviceworker.js\') }}\', {scope: \'./sw/\'})\n .then(registration => {\n console.log("SW registered. Scope: ", registration.scope);\n }).catch(err => { console.error("SW Register failed: ", err); });\n}\nRun Code Online (Sandbox Code Playgroud)\n\n路径内的页面之一/sw/...执行对服务器的提取,以查看与服务器的连接是否可用。它获取的地址是/ping,一个返回一些 JSON 的简单页面。请注意,地址/ping/不在路径内)/sw/...。
// Sample of the bit inside my promise that checks for the server\n// this is the request that is being cached\n\nfetch(\'/ping\')\n .then(function(response) {\n\n if (response.status == 200) {\n console.log(\'%c Server available! \', \'background: #20c997; color: #000\');\n }\n\n })\n .catch(function(err) {\n console.log(\'fetch failed! \', err);\n });\nRun Code Online (Sandbox Code Playgroud)\n\n然而浏览器清楚地显示 serviceWorker 拦截了对/ping.
从 Google Chrome 开发控制台:
\n\n\xe2\x96\xb6 Fetching http://127.0.0.1:8000/ping Request\xc2\xa0{method: "GET", url: "http://127.0.0.1:8000/ping", headers: Headers, referrer: "http://127.0.0.1:8000/sw/create", referrerPolicy: "no-referrer-when-downgrade",\xc2\xa0\xe2\x80\xa6} serviceworker.js:105 \n\xe2\x96\xb6 Fetched over network http://127.0.0.1:8000/ping: Response\xc2\xa0{type: "basic", url: "http://127.0.0.1:8000/ping", redirected: false, status: 200, ok: true,\xc2\xa0\xe2\x80\xa6} \nRun Code Online (Sandbox Code Playgroud)\n\n这没有达到我的预期,因为我只希望 ServiceWorker 拦截以以下地址开头的请求:/sw/...
ServiceWorkers 的规范或预期行为中是否有某处表明它可以缓存对范围内页面发出的获取事件的响应,即使它所访问的地址超出范围?
\n| 归档时间: |
|
| 查看次数: |
1173 次 |
| 最近记录: |