简体   繁体   中英

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 .

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.

So, why isn't url-rewrite working similar to other method?

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
  3. If resource is in cache, it again sends a GET request to fetch the file but with some additional headers

    if-none-match: 7dee9bc1f8cf1:0

    if-modified-since: Tue, 04 Nov 2014 07:34:16 GMT

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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