2

I'd like to hide my image, so I load images using ASP script. But I see the images are not cached, is there a way to cache this kind of images?

My code:

Response.Buffer = True
response.Expires=240
response.CacheControl="Public"
Response.ContentType = "image/jpeg"
Set http = Server.CreateObject("MSXML2.ServerXMLHTTP")
http.open "GET","http://www.test.net/images/" & request.querystring("ID"), False
http.Send
Response.BinaryWrite http.ResponseBody
Set http = Nothing
Response.Flush
Response.End

This file is named test.asp and I call it via test.asp?ID=12345, like that:

<img src="test.asp?ID=12345">

The firebug shows OK for the image to be loaded not 302 not modified.

Is it possible to cache such kind of images?

Jerry2
  • 2,955
  • 5
  • 30
  • 39

1 Answers1

2

There is no reason that ASP page can not be cached, since browser does not know which server side technology generated it. You only need to set proper HTTP header directives. In your case, at the minumum, you need to set Max-Age in the Cache Control directive, for example:

response.CacheControl="public, max-age=68400"

See following article for other useful directives for HTTP case.

Atilla Ozgur
  • 14,339
  • 3
  • 49
  • 69