【发布时间】:2020-02-26 05:14:50
【问题描述】:
我有一个 React 应用程序,每次我重新部署时,用户都告诉我他们看不到更改。我要求他们进行硬重置并清除缓存。我想在推送新版本时破坏浏览器缓存,以便用户看到更改。
我最初使用 react-create-app 来创建应用程序。
我读到 here 你应该在你的 webpack 插件中使用 hash: true 。我这样做了,现在我看到捆绑的反应应用程序现在有一个查询字符串,但现在我收到错误:
Refused to execute script from 'https://example.com/static/js/main.9b80cc8a.js?76de7bb1d01e56c5fcb0' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled
该错误已用 Node.js here 覆盖。我正在使用 express.static
我从这里更改了 web 包:
new HtmlWebpackPlugin({
inject: true,
template: paths.appHtml,
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
}),
到这里:
new HtmlWebpackPlugin({
hash: true,
inject: true,
template: paths.appHtml,
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
}),
我的节点代码是这样的,我觉得是对的:
app.use(express.static(path.join(__dirname, 'public')));
公共目录包含生产构建的应用程序。
如何在应用更新时防止出现此错误并清除浏览器缓存?
【问题讨论】:
标签: node.js reactjs caching webpack