/    Sign up×
Community /Pin to ProfileBookmark

Displaying updated file with ajax

Hey guys.

So, I’ve been using ajax calls to change the contents of a file. After the file is changed I have a script that displays the updated version after x amount of seconds.

It works okay, but the problem I’ve been having is with the updated version displaying itself in ie and safari for windows. It writes the file but it only displays the older version of the file instead of the new updated one. I don’t get this problem in current versions of firefox and opera.

Does anyone have any thoughts on this?

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@mrhooDec 06.2008 — Set a Cache-Control header in the response on the server, with a value like”no-store, no-cache, must-revalidate”.

Or you can add a different tail to the url for each request-

url=url+'?fresh='+new Date().getTime();
Copy linkTweet thisAlerts:
@bals28mjkauthorDec 06.2008 — Thanks mrhoo.

I've had problems in the past getting no-cache headers to work in ie. I've tried about 10 different combinations of headers and it's still wanting to cache, and it's really pissing me off. Do you have a solution for this?
Copy linkTweet thisAlerts:
@Logic_AliDec 06.2008 — How about changing the file's [I]modified[/I] date to a random value after closing it?
Copy linkTweet thisAlerts:
@svidgenDec 06.2008 — Or you can add a different tail to the url for each request-

url=url+'?fresh='+new Date().getTime(); [/QUOTE]

This is the more reliable way to do it. I'm fairly sure that the browser is somewhat free to ignore cache-control and expires directives (pretty sure IE often does so). But if you give the browser the impression that it's never seen the file (by adding a unique query), the browser will [I]always[/I] re-request the document.
Copy linkTweet thisAlerts:
@A1ien51Dec 06.2008 — xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");

Eric
Copy linkTweet thisAlerts:
@bals28mjkauthorDec 06.2008 — @Eric *BING* I might have to buy your book now. ?

Thanks for all the suggestions guys, you've been really helpful.
×

Success!

Help @bals28mjk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...