通过javascript清除浏览器缓存和历史记录,并加载最新的js文件 [英] clear browser cache and history via javascript and load latest js files

查看:930
本文介绍了通过javascript清除浏览器缓存和历史记录,并加载最新的js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过javascript清除浏览器缓存和历史记录 我发现了一些链接,例如:-

how to clear browser cache and history via javascript I found some links like:-

如何清除浏览器历史记录或清除缓存?

如何清除JavaScript中的浏览器哈希历史记录

但是他们没有正确描述如何通过javascript(或jQuery)实现这一目标

but they do not properly described on how this can be achieved via javascript ( or jQuery)

我需要这样做,以便用户不必执行[Ctrl + F5]或手动清除缓存 并在浏览器中加载了最新版本的javascript文件.

I require this so that the user do not have to do a [Ctrl+F5] or manually clear cache and the most recent version of javascript file is loaded in the browser.

主要目的是每次用户访问网站时加载最新的javascript文件. 我在ASP.NET MVC和javascript文件中的应用程序包含在.csHtml文件中.

The main aim is to load the latest javascript files every time the user visits the website. My application in ASP.NET MVC based and javascript files are included in .csHtml file.

推荐答案

还有其他方法可以防止JavaScript文件(或其他文件)被缓存.

There are other ways to prevent a JavaScript file (or other files) from being cached.

只需将一些伪参数附加到url的末尾.例如-

Simply append some dummy parameters to the end of the url. For example -

http://www.yourCoolSite.com/resources/js/main.js?r=SOME_RANDOM_VALUE

您最好在服务器端执行此操作.在PHP中,这看起来像这样-

You would optimally do this on the server side. In PHP, this would look something like this -

echo "http://www.yourCoolSite.com/resources/js/main.js?r=".time();

使用time()函数,我们将当前纪元时间戳附加到URL上,从而保证*该文件每次在浏览器中的外观都会不同.

Using the time() function, we append the current epoch timestamp to the URL and therefore guarantee* that the file will appear different to the browser each time.

*直到2038年,即;)

这篇关于通过javascript清除浏览器缓存和历史记录,并加载最新的js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆