简体   繁体   English

缓存CSS和JS文件

[英]Cache CSS and JS files

When I refresh my website in less than 2-3 minutes, Firebug shows these nice requests: 当我在不到2-3分钟内刷新我的网站时,Firebug会显示这些不错的请求:

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

BUT when I refresh after >3 minutes, I get: 但是当我在> 3分钟后刷新时,我得到:

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

Why my CSS and JS files are downloaded again and images aren't? 为什么我的CSS和JS文件再次下载而图像不是?

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: 我正在使用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>

which sets HTTP header Cache-Control: max-age=86400 ONLY. 设置HTTP标头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? 所以基本上CSS,JS和图像都以同样的方式处理,但不知何故,CSS和JS不会被缓存更长时间......为什么会这样?

Hopefully this will help: http://www.iis.net/ConfigReference/system.webServer/staticContent/clientCache 希望这会有所帮助: http//www.iis.net/ConfigReference/system.webServer/staticContent/clientCache

The <clientCache> element of the <staticContent> 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... <staticContent>元素的<clientCache>元素指定IIS 7及更高版本发送到Web客户端的与缓存相关的HTTP标头,这些标头控制Web客户端和代理服务器将如何缓存IIS 7及更高版本返回的内容...

This occurs with IIS or with the Visual Studio web server? IIS或Visual Studio Web服务器会出现这种情况吗? for some time perceived this behavior while developing (using the VS web server), but when publish it in IIS this not occur anymore. 有一段时间在开发时(使用VS Web服务器)感知到这种行为,但是当在IIS中发布时,这种情况不再发生。

Could this be the bug in Firefox described here ? 这可能是这里描述的Firefox中的错误吗?

You could test this by opening the same page in another browser and check what get's loaded using Fiddler or some other tool. 你可以通过在另一个浏览器中打开相同的页面来测试这个,并检查使用Fiddler或其他工具加载的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM