I have an application with Google Maps API V3 and ASP.Net that uses OverlayView to set an custom icon on the map.
The image of that icon is set on onAdd
event by setting the background CSS property with JavaScript. This image is .png.
This icon position is frequently changed by updates($.ajax) and, on that point, the image is downloaded again from the server. This causes a little blink - icon image disappear when another is downloading. It should change it's position without blinking.
The question is "why browser doesn't caches the image?". The Chrome's Developer Tool shows that these images are coming with MIME Type of "application/octet-stream"
. And on console I see this warning:
Resource interpreted as Image but transferred with MIME type application/octet-stream: "http://localhost:81/Common/Images/Synoptic/bus_b.png"
There's already a question about this on this link but it doens't helped me. I think my problem is more specific.
Well, I found a solution for this. I used a .ashx
file header and controlled the cache there. This is the result:
path = context.Request.MapPath(path + context.Request.QueryString["name"]);
if (File.Exists(path))
{
imageBytes = File.ReadAllBytes(path);
DateTime dt = DateTime.Now.AddYears(1);
context.Response.Cache.SetMaxAge(new TimeSpan(dt.ToFileTime()));
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.ContentType = "image/png";
context.Response.BinaryWrite(imageBytes);
}
else
{
throw new SystemException("Image doesn't exists. '" + path + "'");
}
So the use is:
frmImageCaching.ashx?name=bus_b.png