微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

asp.net-mvc – 缓存CSS和JS文件

当我在不到2-3分钟内刷新我的网站时,Firebug显示了这些不错的请求:
1. /core.css          304 Not modified
2. /core.js           304 Not modified
3. /background.jpg    304 Not modified

但是当我刷新3分钟后,我得到:

1. /core.css          200 OK
2. /core.js           200 OK
3. /background.jpg    304 Not modified

为什么我的CSS和JS文件被再次下载和图像不是?

我使用ASP.NET MVC 3,我不使用[OutputCache],在我的/ Content文件夹(其中所有css,js和img文件存在于子文件夹中)我有这个Web.config

<configuration>
    <system.webServer>
        <staticContent>
            <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
        </staticContent>
    </system.webServer>
</configuration>

它设置HTTP头缓存控制:max-age = 86400 ONLY。所以基本上CSS,JS和图像都是以同样的方式对待的,但是不管怎样,CSS和JS不会被缓存一段较长的时间?为什么呢?

解决方法

希望这将有助于: http://www.iis.net/ConfigReference/system.webServer/staticContent/clientCache

The <clientCache> element of the 07001 element specifies cache-related HTTP headers that IIS 7 and later sends to Web clients,which control how Web clients and proxy servers will cache the content that IIS 7 and later returns…

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐