/    Sign up×
Community /Pin to ProfileBookmark

Refresh external JS file/data changes.

?
What is the best method to assure that the latest external JS or ajax text file changes
are recognized so that older cached information is not used in error?

Is there a force JS to reload command?

<meta> tags?
cookie or local storage settings?

Is this something solvable with JS or is a browser setting by the user/client necessary?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@rnd_meDec 20.2012 — its up to the server to use traditional http cache headers to effectively instruct the browser.

in particular, a Date header is always required.

if you want no cache, send an [I]expires [/I]tag set the same as Date or to a gmt date in the past.

cache-control: private will help with fringe-case older proxies that don't get http1.1, but all browsers since ie7 understand 1.1.

if you want to not always check for new ones, but want to periodically check for updates, you can set [I]expires [/I]to 4 hours in the future, and use the max-age directive in cache-control. this helps performance a lot (compared to always-loading) while ensuring that the client will get a fresh copy the next time they come back to the site.

read up on headers, trust that they work, and you will have few problems assigning the specific and desired behaviors to your script loading.

you can see how good sites setup headers using firebug, and what effect a 200, 304, and far-future-expires headers have on page load performance.


one last thing: don't change the url every time, it's bad for your user's data plan consumption and your site's performance.
Copy linkTweet thisAlerts:
@JMRKERauthorDec 20.2012 — Thank you, 'rnd me', for the information and cautions.

?
×

Success!

Help @JMRKER 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 4.29,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...