如何设置 httpexpires 和 cachecontrol 标头 [英] how to set up both httpexpires and cachecontrol headers

查看:38
本文介绍了如何设置 httpexpires 和 cachecontrol 标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 web.config 中设置 expires 和 cachecontrolhttpExpires 标头按照该问题的答案Expires 和 Cache-control:max-age 有什么区别?

I want to set up both expires and cachecontrol and httpExpires headers in web.config by following the answer on that question What's the difference Expires and Cache-control:max-age?

     <system.webServer>
        <staticContent>
            <clientCache cacheControlCustom="public" cacheControlMaxAge="12:00:00" cacheControlMode="UseMaxAge" />
            <clientCache cacheControlCustom="public" httpExpires="Tue, 19 Jan 2038 03:14:07 GMT" cacheControlMode="UseExpires" />
        </staticContent>
    </system.webServer>

但由于某种原因,当我这样做时,图像变得不可用.

But for some reason images became not available when I am doing that.

我有 Failed to load resource: 服务器响应状态为 500 (Internal Server Error) 每次图像加载错误(我可以在 浏览器开发工具中看到错误控制台).

I've got Failed to load resource: the server responded with a status of 500 (Internal Server Error) error on each image load (I can see that errors in browser dev tools console).

我猜我配置错了?

如果我通过只留下一个来评论任何 clientCache 部分,它会起作用

It would work if I comment any of clientCache section by leaving only single one

如何解决?

更新:刚刚问了另一个相关问题 如何设置httpexpires 和 cachecontrol 标头 web.cofig:

UPDATED: Just asked one more related question how to set up both httpexpires and cachecontrol headers web.cofig:

推荐答案

这个 IIS 客户端缓存页面 声明虽然Expires"和max-age"设置有些类似,但max-age"指令优先于Expires".但是,当一个max-age"clientCache 条目与一个Expires"clientCache 条目并行使用时,IIS 会生成 HTTP 500 错误.

This IIS Client Cache page states that 'While the "Expires" and "max-age" settings are somewhat analagous, the "max-age" directive takes priority over "Expires"'. However, IIS generates HTTP 500 errors when one "max-age" clientCache entry was used in parallel with an "Expires" clientCache entry.

在 IIS 中调整Set Common Headers"时,Expires"和max-age"相互排斥.您可以使用其中一种,但不能同时使用.

The "Expires" and "max-age" are mutually exclusive of one another when adjusting the "Set Common Headers" in IIS. You can use one or the other, but not both.

其他缓存指令可以应用于 Web.config 中的子文件夹或特定文件.请参阅此 stackoverflow 页面关于在 IIS7 中配置缓存内容.

Other cache directives can be applied to subfolders or specific files in Web.config. See this stackoverflow page on configuring cache content in IIS7.

这篇关于如何设置 httpexpires 和 cachecontrol 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆