我在Chrome中遇到了一個非常奇怪的行爲,我的SPA
。我正在使用前端AngularJS
運行本地IIS服務器。我正在使用Gulp
來緩存我所有的Javascript和CSS文件。最近我發現我的網站正在加載舊的HTML文件,這是由於角度$templateCache
,所以我用gulp-angular-templatecache
來解決這個問題,但隨後出現了一個新問題。Chrome繼續緩存我的舊頁面,直到我點擊刷新按鈕
當我打開我的電腦時,啓動IIS服務器並通過在URL欄中輸入localhost
來加載我的應用程序,Chrome從緩存中加載所有內容,以便獲取舊的JS,CSS和HTML文件(我看到了Chrome正在加載一箇舊的index.html
文件),但如果我去其他的路線,如localhost/mainPage
它加載我所有的新文件,一切按預期工作。之後,如果我再次訪問localhost
,則舊網站將再次從緩存中加載!
我不是專家,但它似乎是一個非常奇怪的行爲。這是Chrome的錯誤嗎?是Chrome的故障還是我的AngularJS
SPA
?
在我Web.config
我有這樣的禁用的index.html
緩存:
<!-- Disable index.html cache -->
<location path="index.html">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
這最大化緩存時間爲所有其他文件:
<system.webServer>
<staticContent>
<!-- Cache busting for 1 year (max recommended value) -->
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
</staticContent>
</system.webServer>
我已經附加一個散列到每個文件(cache-bust),這就是問題,chrome不斷收到和舊的HTML文件 – Andres