我有下面的工作箱配置
config.plugins.push(
new GenerateSW({
swDest: 'service-worker.js',
clientsClaim: true,
// Only cache PWA version. Excludes pre-rendered AMP pages
exclude: [/^(?!shell).*index\.html$/],
// PWA routing ie single page app
navigateFallback: '/shell/index.html',
navigateFallbackBlacklist: [
/*\.js.*/
],
}),
)我的快速服务器不缓存服务工作人员。
import serve from 'serve-static'
function setHeaders(res: Response, file: string) {
let cache =
basename(file) === 'service-worker.js'
? 'private,no-cache,no-store,must-revalidate,proxy-revalidate'
: 'public,max-age=31536000,immutable'
return res.setHeader('Cache-Control', cache) // don't cache service worker file
}
app.use(serve(BUILD_LOCATION, { setHeaders }))service-worker.js被返回为最新版本,并对所有资产和shell.html进行预处理。shell.html而不是服务器,资产由服务工作者提供。service-worker.js。service-worker.js,并对所有新的资产进行预处理。相反,我看到了下面的空响应



我在控制台The script has an unsupported MIME type ('text/html').中得到以下错误
因此,看起来服务工作人员正在为shell/index.html服务,而不是为service-worker.js服务服务器。为了验证这一点,我访问了如下所示的view-source:https://localhost/service-worker.js。如何阻止服务工作人员缓存自身。我以为这就是我对navigateFallbackBlacklist所做的

发布于 2019-09-10 18:44:12
在浏览器中转到view-source:https://localhost/service-worker.js将触发https://localhost/service-worker.js的导航请求,然后显示该导航请求的HTTP的文本内容。
对服务工作者的更新通常不是这样获取的--正常的更新流将向您的服务器发出非导航请求。
如果您想要准确地查看service-worker.js响应的内容,我建议在网络面板中单击该请求,然后转到查看器的“响应”面板,例如:

或者,您可以在“隐秘”窗口中访问https://localhost/service-worker.js,即使这将导致导航请求,“隐秘”窗口也不应该有关联的服务工作人员,因此导航请求不会被截获。
https://stackoverflow.com/questions/57738302
复制相似问题