简体   繁体   English

使用url-rewrite进行缓存清除似乎在iis中不起作用

[英]cache busting using url-rewrite doesn't seem to work in iis

To bust the image cache using version string, I used following: 为了使用版本字符串来破坏图像缓存,我使用了以下命令:

<system.webServer>
  <rewrite>
    <rules>
        <rule name="PNG Versioning">
            <match url="(.*).png" />
            <action type="Rewrite" url="{R:0}" appendQueryString="true" />
            <conditions>
                <add input="{QUERY_STRING}" pattern="ver=20190327" negate="true"/>
            </conditions>
        </rule>
    </rules>
</rewrite>
</system.webServer>

But changing the value of version string still ends up in 304 . 但是更改版本字符串的值仍然会在304结束。

If I manually add version string to the image url, on each each update of version string I get a 200 response code as expected. 如果我手动将版本字符串添加到图像url,则每次更新版本字符串时,都会得到200预期的响应代码。

So, why isn't url-rewrite working similar to other method? 那么,为什么url-rewrite无法像其他方法一样工作?

I got the answer. 我得到了答案。 Cache- busting is not possible this way because: 由于以下原因,无法进行缓存清除:

When browser requests a resource: 当浏览器请求资源时:

  1. It checks whether resource is in cache or not 它检查资源是否在缓存中
  2. If resource is not in cache it sends a GET request to fetch the file 如果资源不在高速缓存中,它将发送GET请求以获取文件
  3. If resource is in cache, it again sends a GET request to fetch the file but with some additional headers 如果资源在高速缓存中,它将再次发送GET请求以获取文件,但带有一些其他标头

    if-none-match: 7dee9bc1f8cf1:0 如果不匹配:7dee9bc1f8cf1:0

    if-modified-since: Tue, 04 Nov 2014 07:34:16 GMT 如果修改时间:自周二,2014年11月4日格林尼治标准时间

  4. These additional headers instruct the server to only return the file if above conditions fail. 这些附加头指示服务器仅在上述条件失败时才返回文件。

  5. Adding query string like ?v=1.123 to the url makes the browser think it is a new path/file and hence browser doesn't send the above headers with the GET request. 在网址中添加?v = 1.123之类的查询字符串会使浏览器认为它是新路径/文件,因此浏览器不会将上述标头与GET请求一起发送。

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

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