views:

133

answers:

4
+1  Q: 

Browser caching

Hi,

I am developing a web site which uses lot of images.I would like to make all images are to be stored in browser's cache till some specified time.Now it is stored in browser's cache.However if we refresh the page in browser it is making request to server for particular resource.Server responds with 304 code(NOT MODIFIED).I want to avoid that request also.I am developing application in jsp/servlet.Images wants to be stored in browser for particular time.If the time expires it can send request to server for resources.

Is there any possiblity to implement this?Can anyone provide me help on this.

Thanks.

+3  A: 

There's just no way in which you, working server-side, can stop the browser from checking about things it's caching when it's explicitly being asked to refresh a page -- it's just totally out of your control. You may (and should) claim the cache's validity expires in 2099 or later, but you just cannot force the browse to trust that (or any other) expiration date, period -- programmers who develop browsers have their ideas about how best to serve their customers, and you just can't force their hand.

Alex Martelli
A: 

Theoretically, if the browser had something like Gears installed, then you might be able to store them client-side, and load them with JavaScript instead of plain vanilla HTTP - first checking the local data store, and then going back to your server if the image wasn't found.

But I'm not sure if you can store binary data or images with Gears, et. al.

Chris
A: 

If using Apache, you could use .htaccess files to tweak cache and expiration headers for different folders or file types.

http://www.askapache.com/2006/htaccess/speed-up-sites-with-htaccess-caching.html

David
A: 

I'm pretty sure an explicit refresh in the browser will cause it to reload all the resources, ignorning cache-expiration settings.

n8wrl