简体   繁体   English

强制客户端重新加载我的bundle.js

[英]Force clients to reload my bundle.js

I'm using React and Webpack to create a completely front-end application. 我正在使用React和Webpack创建一个完全前端的应用程序。 I just made some changes to my build. 我刚刚对构建进行了一些更改。 Now my concern is that my users won't get to use the latest bundle but the cached bundle by their browsers. 现在,我担心的是,我的用户将无法使用最新的捆绑软件,而是使用浏览器缓存的捆绑软件。 How can I get them to load the latest bundle? 如何让他们加载最新的捆绑包?

It is not recommended to add a code for loading assets forcefully in client browser as this will result in the slow rendering of application. 不建议添加代码以强制在客户端浏览器中加载资源,因为这将导致应用程序渲染缓慢。

The task you want to achieve can be done by adding a new query parameter version on your script tag and change that version whenever you want to load new code. 要完成的任务可以通过在脚本标签上添加新的查询参数版本并在每次要加载新代码时更改该版本来完成。

something like 就像是

<script type="text/javascript" src="myfile.js?REVISION"></script>

I found a trick. 我发现了一个把戏。 Try adding a query parameter in the script url. 尝试在脚本网址中添加查询参数。

For example: http://example.com/scripts/bundle.js?something=something 例如: http://example.com/scripts/bundle.js?something=something : http://example.com/scripts/bundle.js?something=something

I think that prevents browsers from caching the file. 我认为这可以防止浏览器缓存文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM