Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Ajax keeps reloading images, Rtaher then using cached ones.
Old 09-22-2009, 10:06 AM Ajax keeps reloading images, Rtaher then using cached ones.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,615
Location: UK
Trades: 1
Hi guys,

Ive got some ajax that loads data from a php file then puts that into a div.

Every 5 seconds this runs.

I have a problem where on some older browsers or after you press CTRL+F5 on a recent browser instead of it updating without any images reloading it reloads every image.

Even if they are the same image, It seems to load each one again and again without just using a local copy ( so it doesnt look like everything reloads )

Does anyone have any clue how to stop it from doing this and force it to use a local copy unless the user actually ctrl+f5.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
 
Register now for full access!
Old 09-22-2009, 11:47 AM Re: Ajax keeps reloading images, Rtaher then using cached ones.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,522
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
ctrl+F5 is SUPPOSED to reload everything from the server.

And because it is loading via XMLHTTP (AJAX) rather than the BROWSER processing the request it will download everthing.

AJAX (javascript) knows nothing about the browser cache, so cannot "reload" what the browser has cached
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-22-2009, 12:10 PM Re: Ajax keeps reloading images, Rtaher then using cached ones.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
AJAX (javascript) knows nothing about the browser cache, so cannot "reload" what the browser has cached
Are you sure Chris ?
Because, for me, it's still the browser that makes the request, and it should reuse it's cache if there is a local copy.

What can be the cause of this, though, is a specific configuration of the server.
Like, an "expire" header that is always set to now()-1, or an "etag" that is time based.

Those things can defeat a browser cache.

But for me Lynxus, the answer would be that if you don't manage the server where you make requests yourself, there is nothing you can do.
If the browser don't use the cache, then it means that the server sends headers telling the browser not to use cache, or that the cached version is expired.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-22-2009, 12:36 PM Re: Ajax keeps reloading images, Rtaher then using cached ones.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,522
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It may just apply to IE of course, where the XMLHttp object is a separate entity (ActiveX) from the browser and uses it's own mechanisms to load elements into memory rather hooking into the browser functions.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-22-2009, 01:03 PM Re: Ajax keeps reloading images, Rtaher then using cached ones.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,615
Location: UK
Trades: 1
Quote:
Originally Posted by tripy View Post
Are you sure Chris ?
Because, for me, it's still the browser that makes the request, and it should reuse it's cache if there is a local copy.

What can be the cause of this, though, is a specific configuration of the server.
Like, an "expire" header that is always set to now()-1, or an "etag" that is time based.

Those things can defeat a browser cache.

But for me Lynxus, the answer would be that if you don't manage the server where you make requests yourself, there is nothing you can do.
If the browser don't use the cache, then it means that the server sends headers telling the browser not to use cache, or that the cached version is expired.

I have full access to the server as its a dedicated box.

Its not really the CRTL+F5 thing thats annoying, its the fact that on some browsers its just seems to reload all images anyway each time the ajax request goes through and others it doesnt.

Maybe its just a new feature in newer browsers that dont make it do it.

Just seems strange where lets say i have 20 images ALL the same.
Image.png

however it loads them all seprately , So you can actually see each one being loaded.

I would of expected either NO loading as it should be cached.
Or at least ALL of them appear at the same time. Being the same image n all.

Quite odd tbh.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 09-22-2009, 01:14 PM Re: Ajax keeps reloading images, Rtaher then using cached ones.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,522
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
And the vrowser(s) exhibiting this behaviour is?

Quote:
I would of expected either NO loading as it should be cached.
Or at least ALL of them appear at the same time. Being the same image n all.
Not necessarily HTML rendering doesn't work like that. Each of the images may have a different location in memory and or the cache. Simply being the same file on the server doesn't mean they will be same on the client machine.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-25-2009, 06:28 AM Re: Ajax keeps reloading images, Rtaher then using cached ones.
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
How's your browser configured? Has it set aside an amount for cache? Does it rely on cache or is the content never cached and the page is downloaded every visit?

What are the server headers that are being sent?

The main ones you would want for AJAX would be Expires, Last-Modified and Cache-Control. There are others that may help too like ETags that was mentioned above.

Without knowing these things, it may not be an ajax issue, but you own configuration/setup.

Like most requests made, local cache is usually checked first before it downloads anything new and unless HTTP caching is configured correctly it will be hard to make AJAX read the cache.

What could fail though is if AJAX relies on the POST method, as POST requests are never cached. If the Expires is too short, or has expired will always get new content. If the request made is to a non-caching link, e.g. one that alters it's get request so the browser always believes it's a new page.

I know this may not solve your issue, but hopefully there's some insight as to way it's not working.


Cheers,


MC
__________________
#------------------------------signature---------------------------------------------------------------------------------#
Quote:
I am well recognised for what I don't do than what I do. Chores are just one of those things.
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Reply     « Reply to Ajax keeps reloading images, Rtaher then using cached ones.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.74677 seconds with 12 queries