防止RequireJS缓存所需的脚本 - Prevent RequireJS from Caching Required Scripts

问题:

RequireJS seems to do something internally that caches required javascript files. RequireJS似乎在内部执行缓存所需javascript文件的操作。 If I make a change to one of the required files, I have to rename the file in order for the changes to be applied. 如果我对其中一个必需文件进行了更改,则必须重命名该文件才能应用更改。

The common trick of appending a version number as a querystring param to the end of the filename does not work with requirejs <script src="jsfile.js?v2"></script> 将版本号作为查询字符串参数附加到文件名末尾的常见技巧不适用于requirejs <script src="jsfile.js?v2"></script>

What I am looking for is a way to prevent this internal cacheing of RequireJS required scripts without having to rename my script files every time they are updated. 我正在寻找的是一种方法来防止这种内部缓存RequireJS所需的脚本,而不必在每次更新时重命名我的脚本文件。

Cross-Platform Solution: 跨平台解决方案:

I am now using urlArgs: "bust=" + (new Date()).getTime() for automatic cache-busting during development and urlArgs: "bust=v2" for production where I increment the hard-coded version num after rolling out an updated required script. 我现在正在使用urlArgs: "bust=" + (new Date()).getTime()用于开发期间的自动缓存清除和urlArgs: "bust=v2"用于生产,其中我在推出后增加硬编码版本num更新的必需脚本。

Note: 注意:

@Dustin Getz mentioned in a recent answer that Chrome Developer Tools will drop breakpoints during debugging when Javascript files are continuously refreshed like this. @Dustin Getz在最近的回答中提到,Chrome Developer Tools会在调试期间丢弃断点,此时Javascript文件会不断刷新。 One workaround is to write debugger; 一种解决方法是编写debugger; in code to trigger a breakpoint in most Javascript debuggers. 在代码中,在大多数Javascript调试器中触发断点。

Server-Specific Solutions: 服务器专用解决方案:

For specific solutions that may work better for your server environment such as Node or Apache, see some of the answers below. 对于可能更适合您的服务器环境(如Node或Apache)的特定解决方案,请参阅下面的一些答案。


解决方案:

参考一: https://en.stackoom.com/question/Yt8K
参考二: https://stackoom.com/question/Yt8K
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章