I have a rails app where a user can upload an image. When an image is uploaded, it overwrites the previous image. After an upload, I want to display the new image. When I try to do this, however, the old image (which had the same name) gets displayed - i can even browse around that application, return to the image and still see the old copy - I have to specifically refresh the page to see the new image. Is there any way I can *force* the page to reload the image from the server after and upload? Thanx :) Lindsay
Off the top of my head, this sounds like browser-level caching; i.e. - your broswer (mozilla, IE, etc) is retaining the image locally rather than refetcing. On 6/18/05, Lindsay <hellolindsay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a rails app where a user can upload an image. > When an image is uploaded, it overwrites the previous image. > > After an upload, I want to display the new image. When I try to do > this, however, the old image (which had the same name) gets displayed > - i can even browse around that application, return to the image and > still see the old copy - I have to specifically refresh the page to > see the new image. Is there any way I can *force* the page to reload > the image from the server after and upload? > > Thanx :) > > Lindsay > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Jun 18, 2005, at 12:12 PM, Lindsay wrote:> Is there any way I can *force* the page to reload > the image from the server after and upload? > > Thanx :) > > LindsayI think you can also specify some http headers in the controller to help notify the browser that the information must be refreshed: @headers[''Cache-Control''] = ''private'' @headers[''Pragma''] = ''no-cache'' Duane Johnson (canadaduane) _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 6/18/05, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Jun 18, 2005, at 12:12 PM, Lindsay wrote: > > Is there any way I can *force* the page to reload > the image from the server after and upload? > > Thanx :) > > Lindsay > > I think you can also specify some http headers in the controller to help > notify the browser that the information must be refreshed: > > @headers[''Cache-Control''] = ''private'' > @headers[''Pragma''] = ''no-cache'' >But then the browser has to always redownload the image. Instead of just when it''s changed.
On Jun 19, 2005, at 2:59 PM, Joe Van Dyk wrote:>> @headers[''Cache-Control''] = ''private'' >> @headers[''Pragma''] = ''no-cache'' > > But then the browser has to always redownload the image. Instead of > just when it''s changed.Isn''t that the desired effect? To be honest, I don''t understand caching as I should. How do you tell the browser what the "timestamp" of the image is, so it can update it only when necessary? Duane Johnson (canadaduane)
On Sunday 19 June 2005 05:36 pm, Duane Johnson wrote:> On Jun 19, 2005, at 2:59 PM, Joe Van Dyk wrote: > >> @headers[''Cache-Control''] = ''private'' > >> @headers[''Pragma''] = ''no-cache'' > > > > But then the browser has to always redownload the image. Instead of > > just when it''s changed.CCM > > Isn''t that the desired effect? To be honest, I don''t understand > caching as I should. How do you tell the browser what the > "timestamp" of the image is, so it can update it only when necessary? >The "Last Modified" header. HTTP servers should set this "whenever possible" which to me means any time a ''static'' file is being returned.
* Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> [Jun 18. 2005 22:40]:> On Jun 18, 2005, at 12:12 PM, Lindsay wrote: > > >Is there any way I can *force* the page to reload > >the image from the server after and upload? > > > >Thanx :) > > > >Lindsay > > I think you can also specify some http headers in the controller to > help notify the browser that the information must be refreshed: > > @headers[''Cache-Control''] = ''private'' > @headers[''Pragma''] = ''no-cache'' >But this disables cache for the complete page, not just the single image. I solved this by adding the current time as an URL parameter. now = DateTime.now.to_s render_text "<img src=\"/images/generated.png?#{now}\"/>" This works quite nicely. Except for the flicker effect when reloading the image :-( Klaus
On 20/06/2005, at 6:31 PM, Klaus Kaempf wrote:> I solved this by adding the current time as an URL parameter. > > now = DateTime.now.to_s > render_text "<img src=\"/images/generated.png?#{now}\"/>" > > This works quite nicely. Except for the flicker effect when > reloading the image :-(Try to use HTTP caching instead of this dirty hack. Here''s a great doc with all you need to know on caching: http://www.mnot.net/cache_docs/ - tim lucas
Thanks everyone - i am using the "dirty hack" for now - but i plan on setting the headers properly in the future. Lindsay On 6/20/05, Tim Lucas <t.lucas-l/qNJNvq70OzaBltdDZI6w@public.gmane.org> wrote:> On 20/06/2005, at 6:31 PM, Klaus Kaempf wrote: > > I solved this by adding the current time as an URL parameter. > > > > now = DateTime.now.to_s > > render_text "<img src=\"/images/generated.png?#{now}\"/>" > > > > This works quite nicely. Except for the flicker effect when > > reloading the image :-( > > Try to use HTTP caching instead of this dirty hack. > > Here''s a great doc with all you need to know on caching: > http://www.mnot.net/cache_docs/ > > - tim lucas > >