This Question is Assumed Answered

1 "correct" answer available (5 pts) 14 "helpful" answers available (3 pts)
6 Replies Last post: Sep 5, 2008 7:53 AM by Duke

how to cache image on client side?

Sep 4, 2008 6:18 AM

Click to view RajivGu's profile Level 6 RajivGu 81 posts since
Apr 2, 2008

HI,

In my application,i am making repeated http request to server,here all the images are loaded again and again

which is slowing down my application considerably,is there any way to ensure that images downloaded once should not

be download back. how should i cache the image on client side.

any input on this would be a great help.


Thanks

Rajiv :|


Click to view cbarber's profile Curl cbarber 115 posts since
Sep 27, 2007
1. Re: how to cache image on client side? Sep 4, 2008 8:58 AM

Images along with any other HTTP file should be cached in your web cache. If your images are not being cached it could be for a number of reasons:

  • The HTTP server is configured to immediately expire the content. Typically web servers should be configured to expire all generated content (i.e. CGI scripts etc.) but should have long expirations for static content such as images. You should check the HTTP headers the server is returning for the images to see if they contain an early expiration time or a cache-control header that disables caching. If that is the problem, you will need to fix your server configuration.
  • There is something wrong with the configuration of your HTTP cache on your client machine.On Windows, Curl uses the same cache as IE, so you should check the Windows Internet Options control panel and find the cache settings (in IE 7 this is under General / Browser history / Settings). The default setting to "Automatically" check for newer versions of stored pages is the one you want. You should also make sure that the cache directory exists, is readable and writable and has not been set to a ridiculously small size. On Windows NT there used to be a bug where if the cache was larger than 512MB it would stop working, but I imagine you are probably using a more recent OS and browser.
  • You have loaded the files with file-caching-style set to reload. However, you would obviously know if your application was doing that.
  • You are loading the files from slightly different URLs

Note that if you are resynchronizing your Curl applet every time you reload, then you would expect all images to be synchronized every time, but that should only involve a HEAD request to the server, not a full reload. If your server was not responding to the HEAD requests correctly, then the image would probably be reloaded in that case.


Click to view tiju's profile Level 6 tiju 102 posts since
Oct 17, 2007
2. Re: how to cache image on client side? Sep 4, 2008 9:11 PM
in response to: cbarber

These are helpful bits of info to anyone, Christopher. Thanks.
Click to view RajivGu's profile Level 6 RajivGu 81 posts since
Apr 2, 2008
3. Re: how to cache image on client side? Sep 4, 2008 10:26 PM
in response to: cbarber
Hi,

I have a different approach for this caching.
I'll copy all the images from the web server to my local disk and then will use the images from my local disk which will be faster.
I know there is an "images" folder on the web server hosting multiple image file. Then I tried to copy the the HttpDirectory (whole content/image as recursive) to my local disk. But I'm not able to do this.

Can you plz give a pseudo code for "coping a HttpDirectory to local file system" ?

Thanks

Rajiv
Click to view friedger's profile MVP friedger 108 posts since
Jan 13, 2008
4. Re: how to cache image on client side? Sep 5, 2008 12:16 AM
in response to: RajivGu

I would doubt that using images from the local disk are faster than using images from the browser cache.

If you really want to copy a HttpDirectory than you must impose some requirements on the web server that it returns the list of files in a certain format. So, altogether that doesn't look like a good solution.

Are there any reasons why you want to cache the files yourself?

Friedger

Click to view RajivGu's profile Level 6 RajivGu 81 posts since
Apr 2, 2008
5. Re: how to cache image on client side? Sep 5, 2008 1:41 AM
in response to: friedger

Hi friedger,

Thanks for your suggestion,

We have a specific need of because when ever we are making any http request to server this images are getting downloaded also,

any painting or repainting of control also downloads the image from server,it is creating huge overhead on the server and

response in very slow.

For e.g. when i sort the column of recordgrid then images used in column are downloaded for every row from server. i have checked using ethereal packet filter and caching is not working,

I want it to be one time activity rather than downloading everytime,whenever i do any activity over my application, here in recordgrid case this images should

be downloaded,at application startup and later on should be used from cache and request should not go to server.

thanks,

Rajiv

Click to view Duke's profile Curl Duke 154 posts since
Oct 17, 2007
6. Re: how to cache image on client side? Sep 5, 2008 7:53 AM
in response to: RajivGu
You need to figure out the reason that the images are not being cached, as cbarber outlined in detail. Have you checked each of his reasons that the image files might be getting fetched each time?