使用 ASP.NET 和 IIS 7.5 控制浏览器缓存

发布于 2024-11-19 12:11:23 字数 851 浏览 4 评论 0原文

Google PageSpeed 建议我的网站优先考虑以下内容。

以下可缓存资源的新鲜生命周期较短。 指定以下内容至少在未来一周内到期 资源:

并建议进一步阅读

我使用的是 Windows Server 2008 r2、.net Framework 4.0、asp.net 和 IIS 7.5。如何延长某些文件的缓存有效期?

我尝试了以下 web.config,但它不起作用。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <sessionState mode="Off" />
    </system.web>
    <system.webServer>
        <staticContent>
          <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="10.00:00:00" />
        </staticContent>
    </system.webServer>
</configuration>

Google PageSpeed suggests the following this for my website as a high priority.

The following cacheable resources have a short freshness lifetime.
Specify an expiry of at least one week in the future for the following
resources:

And suggests further reading.

I am using Windows Server 2008 r2, .net framework 4.0, asp.net and IIS 7.5. How can I increase the cache expiry for some files?

I've tried the following web.config, but it doesn't work.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <sessionState mode="Off" />
    </system.web>
    <system.webServer>
        <staticContent>
          <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="10.00:00:00" />
        </staticContent>
    </system.webServer>
</configuration>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天赋异禀 2024-11-26 12:11:23

您确定这不起作用吗?我只是用一张图像敲出了一个简单的页面作为测试。准确添加您的配置部分并签入 firebug。

这是标题。

在此处输入图像描述

对我来说看起来不错。

Are you sure this is not working. I just knocked up a simple page with a single image as a test. Added your config section exactly and checked in firebug.

Here are the headers.

enter image description here

Looks ok to me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文