Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
422 views
in Technique[技术] by (71.8m points)

javascript - 清除JavaScript中的缓存(Clear the cache in JavaScript)

How do I clear a browsers cache with JavaScript?(如何使用JavaScript清除浏览器缓存?)

We deployed the latest JavaScript code but we are unable to get the latest JavaScript code.(我们部署了最新的JavaScript代码,但无法获取最新的JavaScript代码。) Editorial Note: This question is semi-duplicated in the following places, and the answer in the first of the following questions is probably the best.(编者注:该问题在以下地方被半复制,以下第一个问题的答案可能是最好的。) This accepted answer is no longer the ideal solution.(这个公认的答案不再是理想的解决方案。) How to force browser to reload cached CSS/JS files?(如何强制浏览器重新加载缓存的CSS / JS文件?) How can I force clients to refresh JavaScript files?(如何强制客户端刷新JavaScript文件?) Dynamically reload local Javascript source / json data(动态重新加载本地Javascript源/ json数据)   ask by translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can call window.location.reload(true) to reload the current page.(您可以调用window.location.reload(true)重新加载当前页面。)

It will ignore any cached items and retrieve new copies of the page, css, images, JavaScript, etc from the server.(它将忽略所有缓存的项目,并从服务器检索页面,css,图像,JavaScript等的新副本。) This doesn't clear the whole cache, but has the effect of clearing the cache for the page you are on.(这不会清除整个缓存,但是会清除您所在页面的缓存。) However, your best strategy is to version the path or filename as mentioned in various other answers.(但是,最好的策略是按照其他答案中所述的方式对路径或文件名进行版本控制。) In addition, see Revving Filenames: don't use querystring for reasons not to use ?v=n as your versioning scheme.(另外,请参阅修订文件名:由于不使用?v=n作为版本控制方案,因此请勿使用querystring 。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...