Microsoft KB Archive/246960: Difference between revisions

From BetaArchive Wiki
m (Text replacement - "<" to "<")
m (Text replacement - """ to """)
 
(One intermediate revision by the same user not shown)
Line 57: Line 57:
Use one of the following two methods to make sure that graphic files expire so that they are not cached by browsers:
Use one of the following two methods to make sure that graphic files expire so that they are not cached by browsers:
<ul>
<ul>
<li>Use Internet Information Server's &quot;Custom HTTP Headers&quot; feature to add standard headers that tell the browser to either &quot;expire&quot; or to not cache the images. This technique works best when all the images are stored on the server's hard disk in a few folders. Configure the folders so that the desired headers are applied to all content served out of those folders.<br />
<li>Use Internet Information Server's "Custom HTTP Headers" feature to add standard headers that tell the browser to either "expire" or to not cache the images. This technique works best when all the images are stored on the server's hard disk in a few folders. Configure the folders so that the desired headers are applied to all content served out of those folders.<br />
<br />
<br />
To do so, open the Internet Services Manager and navigate to the folder that contains the images. In the '''Properties''' dialog box for the folder, select '''HTTP Headers''', and then click '''Add'''. Type a header name, such as <span class="kbd userinput"> cache-control</span> and its value, such as <span class="kbd userinput"> no-cache</span>.<br />
To do so, open the Internet Services Manager and navigate to the folder that contains the images. In the '''Properties''' dialog box for the folder, select '''HTTP Headers''', and then click '''Add'''. Type a header name, such as <span class="kbd userinput"> cache-control</span> and its value, such as <span class="kbd userinput"> no-cache</span>.<br />
Line 71: Line 71:
<li>With applications for which image files do not have a centralized location, you can write an Internet Server API (ISAPI) filter that examines the mime type of the outgoing responses and applies a specific set of HTTP headers to certain packets.<br />
<li>With applications for which image files do not have a centralized location, you can write an Internet Server API (ISAPI) filter that examines the mime type of the outgoing responses and applies a specific set of HTTP headers to certain packets.<br />
<br />
<br />
For additional information regarding ISAPI, search http://msdn.microsoft.com for &quot;ISAPI&quot; or visit the support site [http://support.microsoft.com/?scid=http%3a%2f%2fsupport.microsoft.com%2fsupport%2fisapi http://support.microsoft.com/support/isapi].</li></ul>
For additional information regarding ISAPI, search http://msdn.microsoft.com for "ISAPI" or visit the support site [http://support.microsoft.com/?scid=http%3a%2f%2fsupport.microsoft.com%2fsupport%2fisapi http://support.microsoft.com/support/isapi].</li></ul>


Note that if the browser already has a cached copy of a particular graphic when the headers are implemented, it may be necessary to empty the browser's cache before the browser will consistently rerequest a given image. To empty the cache in Internet Explorer 5 or later, from the '''Tools''' menu, select '''Internet Options''', and then click '''Delete Files'''.
Note that if the browser already has a cached copy of a particular graphic when the headers are implemented, it may be necessary to empty the browser's cache before the browser will consistently rerequest a given image. To empty the cache in Internet Explorer 5 or later, from the '''Tools''' menu, select '''Internet Options''', and then click '''Delete Files'''.
Line 79: Line 79:
<div class="indent">
<div class="indent">


<img src=graphicserver.asp?id=234&gt;
<img src=graphicserver.asp?id=234>





Latest revision as of 12:50, 21 July 2020

Article ID: 246960

Article Last Modified on 7/1/2004



APPLIES TO

  • Microsoft Internet Information Server 4.0



This article was previously published under Q246960

SUMMARY

Web sites that change graphic images frequently but utilize the same names for those images face a potential problem because browsers may cache the images and not rerequest them when they display the page.

A scenario that is becoming more common is a site that generates real-time reports every few minutes and saves each report as an image. If browsers cache the image, the updated reports may not be displayed.

This article describes two recommended solutions and one that is generally not recommended.

MORE INFORMATION

Use one of the following two methods to make sure that graphic files expire so that they are not cached by browsers:

  • Use Internet Information Server's "Custom HTTP Headers" feature to add standard headers that tell the browser to either "expire" or to not cache the images. This technique works best when all the images are stored on the server's hard disk in a few folders. Configure the folders so that the desired headers are applied to all content served out of those folders.

    To do so, open the Internet Services Manager and navigate to the folder that contains the images. In the Properties dialog box for the folder, select HTTP Headers, and then click Add. Type a header name, such as cache-control and its value, such as no-cache.

    Headers required to ensure that graphics are not cached include:

    cache-control:no-cache
    pragma:no-cache
    expires:0

  • With applications for which image files do not have a centralized location, you can write an Internet Server API (ISAPI) filter that examines the mime type of the outgoing responses and applies a specific set of HTTP headers to certain packets.

    For additional information regarding ISAPI, search http://msdn.microsoft.com for "ISAPI" or visit the support site http://support.microsoft.com/support/isapi.

Note that if the browser already has a cached copy of a particular graphic when the headers are implemented, it may be necessary to empty the browser's cache before the browser will consistently rerequest a given image. To empty the cache in Internet Explorer 5 or later, from the Tools menu, select Internet Options, and then click Delete Files.

Not Recommended Due to Performance Lag

There is one technique that was commonly used in the past that is no longer preferred because it degrades performance. This method is to set HTTP headers on graphic images to have the client image tag reference an Active Server Pages (ASP) page as such:

<img src=graphicserver.asp?id=234>


In this technique, the ASP page then uses the ID to read a specific image from the hard drive or database and uses Response.AddHeader and Response.BinaryWrite to stream the appropriate bits to the client with the desired HTTP headers.

This technique does offer some advantages, such as the ability to manipulate the binary stream on the fly. But if your goal is merely to add HTTP headers, avoid it because of the performance loss.


Additional query words: no-cache

Keywords: kbhowto KB246960