加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 00:25:37 所属栏目:asp.Net 来源:网络整理
导读:当我在不到2-3分钟内刷新我的网站时,Firebug显示了这些不错的请求: 1. /core.css 304 Not modified2. /core.js 304 Not modified3. /background.jpg 304 Not modified 但是当我刷新3分钟后,我得到: 1. /core.css 200 OK2. /core.js 200 OK3. /background
当我在不到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…

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读