問題:
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