缓存CSS和JS文件 [英] Cache CSS and JS files
问题描述
当我刷新我的网站在不到2-3分钟,萤火显示了这些漂亮的请求:
When I refresh my website in less than 2-3 minutes, Firebug shows these nice requests:
1. /core.css 304 Not modified
2. /core.js 304 Not modified
3. /background.jpg 304 Not modified
但是当我> 3分钟后刷新,我得到:
BUT when I refresh after >3 minutes, I get:
1. /core.css 200 OK
2. /core.js 200 OK
3. /background.jpg 304 Not modified
为什么我的CSS和JS文件被再次下载和图像都没有?
我使用ASP.NET MVC 3,我不使用 [的OutputCache]
,并在我的 /内容
文件夹(其中所有的CSS,JS和IMG文件住在子文件夹)我有这样的Web.config文件:
I'm using ASP.NET MVC 3, I DON'T use [OutputCache]
, and in my /Content
folder (where all css, js and img files live in subfolders) I have this Web.config:
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
</system.webServer>
</configuration>
这台HTTP头缓存控制:最大年龄= 86400
ONLY。所以基本上CSS,JS和图像的处理方式相同,但不知何故,CSS和JS没有得到缓存更长的时间......这是为什么?
which sets HTTP header Cache-Control: max-age=86400
ONLY. So basically CSS, JS and images are treated the same way, but somehow CSS and JS don't get cached for a longer period... why is that?
推荐答案
希望这将有助于:<一href=\"http://www.iis.net/ConfigReference/system.webServer/staticContent/clientCache\">http://www.iis.net/ConfigReference/system.webServer/staticContent/clientCache
这篇关于缓存CSS和JS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!