Welcome Guest, Not a member yet? Register   Sign In
How to solve browser image caching issue right after uploading a new image
#1

[eluser]mi6crazyheart[/eluser]
Hey Guys,
I've just stuck with this image caching issue. Can any body have any idea solve to it...

My pro: I've an application having a "user profile" page where each user has it's own image. With that there is "upload new image" link for the profile. So, when user when click on that link for uploading a new image.. the image is getting uploaded & again control redirected to the "user profile" page.

But, my problem is when control redirected to the "user profile" page right after uploading a new image.. the profile page still shows the old image(which has cached by browser).

So, is there any way to get the new fresh image(which has just uploaded) after redirecting to the "user profile" page.

Thx in advance Smile
#2

[eluser]toopay[/eluser]
use 'refresh' within redirect?
#3

[eluser]Nick_MyShuitings[/eluser]
If you are using any sort of advanced caching features (squid/varnish) then make sure to figure out a way to send a cache buster header along with it.
#4

[eluser]Aken[/eluser]
A) Rename the image, using perhaps a time stamp (what I would do).
B) Add a cache-busting extension, using time() for example: userprofileimage.jpg?987567923
C) Use .htaccess or similar to tell the browser to never cache the image (not recommended).
#5

[eluser]toopay[/eluser]
This is trivial stuff. You only need to give some 'flag' (either by session or other params), and if the flag is on, at the redirected page (success page/controller) you response with some redirect to the same page with refresh function. Unless you did use some fancy stuff of cache mechanism, i don't see playing with HTTP header-cache is the solution.
#6

[eluser]mi6crazyheart[/eluser]
Sorry peoples, for late replying. I'd some serious problem in my net connection in my area and thx a lot for all of u'r quick replies.

BDW, i prefer to use that sending timestamp(by php time() ) value with image link. That's really working well.
#7

[eluser]CroNiX[/eluser]
I would use the file last modified time as the timestamp instead of the current time. Then the timestamp will only change if the file changes and will then get recached in the browser. If you don't you won't be using cache at all as it will load the image each and every time even if it hasn't changed. Probably not what you want.
#8

[eluser]Unknown[/eluser]
[quote author="CroNiX" date="1304814459"]I would use the file last modified time as the timestamp instead of the current time. Then the timestamp will only change if the file changes and will then get recached in the browser. If you don't you won't be using cache at all as it will load the image each and every time even if it hasn't changed. Probably not what you want.[/quote]

Keep in mind - that
Code:
filemtime()
Returns the time the file was last modified, or
Code:
FALSE
on failure. The time is returned as a Unix timestamp, which is suitable for the
Code:
date()
function.

In case of false - you can apply current timestamp. This should work well.




Theme © iAndrew 2016 - Forum software by © MyBB