How do I get browser to cache images, css etc..?

P

Peter Row

Hi,

I have a site were the pages are dynamically generated on demand.
These pages like any static html page may contain image tags and
references to CSS files.

All the images and CSS files etc... are stored in a database so in the
HTML produced for the page the source of an image, for example,
might be:
src=http://www.mysite.com/Res/3/logo.gif

The DLL that runs my site contains a HttpModule that parses each
request when it sees a URL with Res/X/filename in it it extracts the
number X and uses it and the filename to lookup the data in the
database and then does a Response.Write or Response.BinaryWrite
depending on the type of data.

Before it actually writes the data back to the browser it:

With Response
.Expires = 0
.Buffer = True
.Clear()
.AddHeader("Last-modified",......)
.ContentType = Ctype(....., string)
.Cache.SetCacheability(HttpCacheability.Public)
.AddHeader("content-disposition", "filename=" & ....)

.... the decisision of either .Write or .BinaryWrite
End With

However I can see when running through VS.NET that each
time the you visit the page the images etc... are reloaded.
This makes it even worse when you try to load JS to preload
images for roll-over effects, as this JS actually has no effect
and both over and off images a reloaded everytime.

Anybody have any ideas?

Regards,
Peter
 
K

Kevin Spencer

You set Expires to 0, which will cause the browser to request the image from
the server every time.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
P

Peter Row

Hi,

Doh!
Yes that's right, plus I hadn't upgraded the code to use the prefered
Cache object property instead of the compatibility property Expires.

This was a porting job from VB6 webclasses.

Thanks for the reply,

Regards,
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top