IIS 8.0 添加了 Expires header 和 Cache-Control
IIS 8.0 add both Expires header and Cache-Control
我可以看到 Whosebug 添加了 Expires
和 Cache-Control
的图像,css,js 等,所以我尝试做同样的事情,我试过 this 文章
web.config
<location path="Content">
<system.webServer>
<staticContent>
<clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge"
cacheControlMaxAge="365.00:00:00" />
<clientCache cacheControlMode="UseExpires" httpExpires="Mon, 01 May 2023 00:00:00 GMT" />
</staticContent>
</system.webServer>
</location>
当我尝试访问内容文件夹中的 css 文件时:http://localhost:11111/Content/bootstrap.min.css
我收到以下错误
错误:
HTTP Error 500.19 -
Internal Server Error The requested page cannot be accessed because the related configuration data for the page
is invalid.
Module CustomErrorModule
Notification SendResponse
Handler StaticFile
Error Code 0x8007000d
Config Error Configuration element 'clientCache' already defined
我知道 clientCache
已经定义了,但我很担心并且想知道如何设置 Cache-Control 和 Expires 作为响应 headers ?
任何帮助都会很棒。
更新:
正如@Vitaly Kulikov 在评论中回答和讨论的那样,并使用 this and this posts i came to conclusion that in IIS we can's set both Expires and Cache-Control
in web.config, so i have planned to use OutputCache to set Expires for images at least and it works with 0.9 milliseconds 延迟。希望能帮助某人。
根据规范,您无法同时拥有它们。但你没有理由这样做,你对他们中的任何一个都没有问题。
如果您查看 Chrome 来源 code,浏览器中的缓存有几个简单的规则
第一个:
The max-age directive takes priority over Expires, so if max-age is present
in a response, the calculation is simply: freshness_lifetime = max_age_value
第二个:
Otherwise, if Expires is present in the response, the calculation is: freshness_lifetime = expires_value - date_value
第三名:
If we missed previous steps and "cache-control" != "must-revalidate", then browser has one more caching rule: It caches resource for 10% of a time passed since last modified date of a resource.
就是这样,没有更多规则了。
我可以看到 Whosebug 添加了 Expires
和 Cache-Control
的图像,css,js 等,所以我尝试做同样的事情,我试过 this 文章
web.config
<location path="Content">
<system.webServer>
<staticContent>
<clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge"
cacheControlMaxAge="365.00:00:00" />
<clientCache cacheControlMode="UseExpires" httpExpires="Mon, 01 May 2023 00:00:00 GMT" />
</staticContent>
</system.webServer>
</location>
当我尝试访问内容文件夹中的 css 文件时:http://localhost:11111/Content/bootstrap.min.css
我收到以下错误
错误:
HTTP Error 500.19 -
Internal Server Error The requested page cannot be accessed because the related configuration data for the page is invalid.
Module CustomErrorModule Notification SendResponse Handler StaticFile Error Code 0x8007000d
Config Error Configuration element 'clientCache' already defined
我知道 clientCache
已经定义了,但我很担心并且想知道如何设置 Cache-Control 和 Expires 作为响应 headers ?
任何帮助都会很棒。
更新:
正如@Vitaly Kulikov 在评论中回答和讨论的那样,并使用 this and this posts i came to conclusion that in IIS we can's set both Expires and Cache-Control
in web.config, so i have planned to use OutputCache to set Expires for images at least and it works with 0.9 milliseconds 延迟。希望能帮助某人。
根据规范,您无法同时拥有它们。但你没有理由这样做,你对他们中的任何一个都没有问题。
如果您查看 Chrome 来源 code,浏览器中的缓存有几个简单的规则
第一个:
The max-age directive takes priority over Expires, so if max-age is present in a response, the calculation is simply: freshness_lifetime = max_age_value
第二个:
Otherwise, if Expires is present in the response, the calculation is: freshness_lifetime = expires_value - date_value
第三名:
If we missed previous steps and "cache-control" != "must-revalidate", then browser has one more caching rule: It caches resource for 10% of a time passed since last modified date of a resource.
就是这样,没有更多规则了。