Your basket is currently empty

How to disable caching of specific MIME types

Abstract

Website administrators may need to periodically disable the caching of content that changes frequently. This article describes a method to disable caching of document types.

What is a MIME type?

MIME stands for "Multipurpose Internet Mail Extensions", which refers to a way of configuring browsers or mail clients to view files that are in multiple formats based on a "MIME type." "MIME mapping" is a process by which Internet Information Server (IIS) "maps" files by their extensions to a particular MIME type. For example, a file with the extension .htm has a MIME type of "text/html", whereas a file with the extension .gif has a MIME Type of "image/gif".

When a request is made by a client for a particular file, IIS uses the MIME map to determine the correct MIME type to tell a client it will be receiving. IIS contains a large list of default MIME types to use and will return a MIME type of "application/octet-stream" for any file extension that is not explicitly mapped.

How to disable caching of .gif images

The following steps describe an unsupported method of tricking IIS using Windows Scripting Host (WSH) and Active Directory Service Interfaces (ADSI) into returning a "no-cache" header for a specific MIME type, in this case .gif files, for an entire Web server by modifying the IIS metabase.

Option Explicit

Dim boolFound
Dim intCount
Dim intMimeMap
Dim objMimeMap
Dim varMimeMap
Dim varMimeExt
Dim varMimeTyp

' specify the extension and MIME type to work with
varMimeExt = ".gif"
' NOTE - this entry stores an extra HTTP header with the MIME information
' this "tricks" IIS into sending the extra cache control header
varMimeTyp = "image/gif" & vbCrLf & "Cache-Control: no-cache"

' create the ADSI object & current MIME map at that path
Set objMimeMap = GetObject("IIS://localhost/w3svc")
varMimeMap = objMimeMap.GetEx("MimeMap")

' get the MIME map count & set search status to false
intCount = UBound(varMimeMap) + 1
boolFound = False

' loop through MIME map searching for existing extension information
For intMimeMap = 0 to intCount - 1
If varMimeMap(intMimeMap).Extension = varMimeExt Then
boolFound = True
Exit For
End If
Next

' if no extension information is found, create the new mapping
If boolFound = False Then
intMimeMap = intCount
ReDim Preserve varMimeMap(intMimeMap)
Set varMimeMap(intMimeMap) = CreateObject("MimeMap")
varMimeMap(intMimeMap).Extension = varMimeExt
End If

' store the new information in the MIME map
varMimeMap(intMimeMap).MimeType = varMimeTyp
objMimeMap.PutEx 2,"MimeMap",varMimeMap
objMimeMap.SetInfo

Execute the following command to modify the metabase:CSCRIPT %SystemDrive%\InetPub\AdminScripts\MimeChange.vbs

Future requests for .gif files will now returned with the desired "no-cache" header.


Published Wednesday, June 02, 2004