Issue with caching of .PNG files in IE

I’m running a Rails application with WEBrick server. We are displaying
an Image from the server to the Client (Browser). First time on the
browser everything looks fine, upon clicking the link, it contacts the
server and displays in IE brwoser the image that was stored on the
server.

But in case if the image gets changed on the server(File Name being the
same), then even though i click the refresh button on IE, the Browser
still Loads the old image !!!. Has any body seen the above problem. I
think IE is caching the IMAGE file and it does not clear the chache even
though i click the link or refresh the whole page to get the new image
from the server?

Any ideas? kindly pl let me know…

I’m running on Webrick Server.

Thank You,
Dinesh

Dinesh U. wrote:

Any ideas? kindly pl let me know…

Thank You,
Dinesh

You might want to try setting the IE cache setting within IE’s Options
to ‘Every visit to the page’ - I know that in the past having it set to
‘Automatic’ would cause problems seeing updates even when I was
specifically refreshing the page

hope it helps,
Chris

Hi Jim,

Thanks for your reply.

In the “show.rhtml” page i’m having this code which uses AJAX to get the
image Asynchronously . After that the image is rendered to the client…


show.rhtml

<%= link_to_remote(:update => ‘updatediv’,
:url => { :action => :get_images }) %>


In the “contoller” i’m having this action

def get_images
@responseImage="/images/myImages/Image1.png"
end


In the “view” i’m having this code…
<%= @responseImage %>


So can send_date or send_file can solve the above problem ??

Thank You,
Dinesh

Jim C. wrote:

On Jun 16, 2006, at 9:19 PM, Dinesh U. wrote:

But in case if the image gets changed on the server(File Name being the
same), then even though i click the refresh button on IE, the Browser
still Loads the old image !!!. Has any body seen the above problem. I

How are you sending the image? I use send_data, and switch off the
cacheing completely (because my image is generated again for every
request)

     # Explicitly switch off image cacheing
     expires_now
     send_data(session[:image], :type=>"image/png",

:disposition=>“inline”)

This isn’t a good solution for images that only change sometimes, but
it might help you to find a better solution.

-jim

Hi Chris,

Thanks for the reply.

I’m already having the Setting on my browser as ‘Every visit to the
page’.

But still no luck!! Any other ways ?

Dinesh

Chris wrote:

Dinesh U. wrote:

Any ideas? kindly pl let me know…

Thank You,
Dinesh

You might want to try setting the IE cache setting within IE’s Options
to ‘Every visit to the page’ - I know that in the past having it set to
‘Automatic’ would cause problems seeing updates even when I was
specifically refreshing the page

hope it helps,
Chris

On Jun 16, 2006, at 9:19 PM, Dinesh U. wrote:

But in case if the image gets changed on the server(File Name being the
same), then even though i click the refresh button on IE, the Browser
still Loads the old image !!!. Has any body seen the above problem. I

How are you sending the image? I use send_data, and switch off the
cacheing completely (because my image is generated again for every
request)

     # Explicitly switch off image cacheing
     expires_now
     send_data(session[:image], :type=>"image/png",

:disposition=>“inline”)

This isn’t a good solution for images that only change sometimes, but
it might help you to find a better solution.

-jim

Jim,

In your case you are also displaying the image finally in the browser
itself rt may be in a’div’ element using ‘send_data’? with “inline”
otion, then it should work for me also rt?

Dinesh

Jim C. wrote:

On Jun 16, 2006, at 10:09 PM, Dinesh U. wrote:

So can send_date or send_file can solve the above problem ??

Erm, no … but expires_now may still help, in controller method
get_images.

On Jun 16, 2006, at 11:51 PM, Dinesh U. wrote:

In your case you are also displaying the image finally in the browser
itself rt may be in a’div’ element using ‘send_data’? with “inline”
otion, then it should work for me also rt?

Yes – my controller’s view generates an tag which is a reference
to another controller method, which uses send_data to return the image
inline. You could do that if you wanted to :slight_smile: However, just using
‘expires_now’ for every image is a bit of a large hammer; it depends on
how often your images really change, and how much caching you want the
clients to be able to do.

and it’s method ‘reflectpng’ that used send_data.

-jim

2006/6/16, Dinesh U. [email protected]:

though i click the link or refresh the whole page to get the new image
from the server?

Any ideas? kindly pl let me know…

I’m running on Webrick Server.

image_tag or image_path can do this. or:
<img src="<%= “web_path.png?#{File.mtime(full_path.png).to_i}” %>" />

On Jun 16, 2006, at 10:09 PM, Dinesh U. wrote:

So can send_date or send_file can solve the above problem ??

Erm, no … but expires_now may still help, in controller method
get_images.

Hi Jim

Thanks for your response. I tried with send_data using the tag and
it works fine !!!.

But my problem is i want to do it through AJAX, and i’m not sure how to
do it with AJAX.

ie. when we call the link_to_remote(…), it emits the output using the
:update

ie. we can define an empty

like this and we
can ask :update=>‘updatediv’, which will emit the output of
link_to_remote into the div element which is fine.

But in our case, in the contoller i’m using send_file like this
send_file(‘public/images/myImage.png’,type=>“image/png”,:disposition=>“inline”),
so the AJAX when it receives this file it will update in the ‘updatediv’
element. But i want to use tag here, ie get the updates from AJAX
and update it using the tag, i still dont know whethere it makes
sense or not.

ie. bottom line -> AJAX + send_file + tag is what i’m trying to do
so that i will…but still no luck and struggling…:slight_smile:

Thanks again for your kind replies…

Dinesh

Jim C. wrote:

On Jun 16, 2006, at 11:51 PM, Dinesh U. wrote:

In your case you are also displaying the image finally in the browser
itself rt may be in a’div’ element using ‘send_data’? with “inline”
otion, then it should work for me also rt?

Yes – my controller’s view generates an tag which is a reference
to another controller method, which uses send_data to return the image
inline. You could do that if you wanted to :slight_smile: However, just using
‘expires_now’ for every image is a bit of a large hammer; it depends on
how often your images really change, and how much caching you want the
clients to be able to do.

and it’s method ‘reflectpng’ that used send_data.

-jim

On Mon, Jun 19, 2006 at 09:00:38AM +0200, Guest wrote:

But in our case, in the contoller i’m using send_file like this
send_file(‘public/images/myImage.png’,type=>“image/png”,:disposition=>“inline”),
so the AJAX when it receives this file it will update in the ‘updatediv’
element. But i want to use tag here, ie get the updates from AJAX
and update it using the tag, i still dont know whethere it makes
sense or not.

I had a really ugly solution to this, with the original ajax call
returning the HTML , and passing in some parameters to the src of
the image tag … but I suspect you would be able to simplify this using
RJS these days. RJS gets rid of the :update argument, and gives you a
pure Ruby environment where you can update as many different page
sections as you like …

But this isn’t really a cacheing question any more, so perhaps starting
a new message thread asking about that would be a good idea.

-jim

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs