by Mads Kristensen
26. August 2006 09:37
Internet Explorer and the Gecko based browsers (Firefox, Netscape and Mozilla) have
different ways of managing their internal cache. The speed of the browser cache is
much faster that a server caching, so be sure to do your client-side caching cross
browser friendly.
The Gecko based browsers uses the ETag header and Internet Explorer uses the Last-Modified
header, so you have to set both of them to make it work. Here’s a simple method that
does just that.
private void SetCachingHeaders(DateTime lastModified)
{
Response.Cache.SetLastModified(lastModified);
Response.Cache.SetETag(lastModified.ToString());
}
If you serve an image or some other file from ASP.NET, you can make the browser cache
dependant of the file you are serving. That means that whenever the file changes,
so will the client- and server cache and it all happens automatically.
private void SetCachingHeaders(string fileName)
{
context.Response.AddFileDependency(fileName);
context.Response.Cache.SetETagFromFileDependencies();
context.Response.Cache.SetLastModifiedFromFileDependencies();
}
* Only $4.95/month ASP.NET & Windows 2008 + IIS 7 Hosting! FREE SQL Included
14368d0c-926f-48da-9511-a71fc8531f62|1|4.0
Tags:
ASP.NET