IIS - 为每种文件类型设置缓存控制头 [英] IIS - setting cache-control header per file type

查看:464
本文介绍了IIS - 为每种文件类型设置缓存控制头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的js,css和html文件设置不同的缓存控制头值。
我知道在每个文件夹的基础上设置它的选项,但我的应用程序在同一个文件夹中有html和js文件。

I'd like to set different cache-control header values for my js,css and html files. I know about the option to set it on a per-folder basis but my app has html and js files in the same folder.

甚至可能在IIS中?

推荐答案

在IIS 7+中使用IIS出站重写规则是可行的。例如。如果要使所有.html页面无效,请在web.config的outboundRules部分中创建以下出站规则(在安装IIS重写模块之后):

This is possible in IIS 7+ using IIS outbound rewrite rules. Eg. if you want to invalidate all .html pages, create the following outbound rule (after installing the IIS rewrite module) in the outboundRules section of the web.config:

<outboundRules>
  <rule name="AdjustCacheForHTMLPages" preCondition="IsHTMLFile">
    <match serverVariable="RESPONSE_Cache-Control" pattern=".*" />
    <action type="Rewrite" value="no-cache, no-store, must-revalidate" />
  </rule>
  <preConditions>
    <preCondition name="IsHTMLFile">
      <add input="{REQUEST_FILENAME}" pattern=".*\.html" />
    </preCondition>
  </preConditions>
</outboundRules>

这篇关于IIS - 为每种文件类型设置缓存控制头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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