无论我做什么,JavaScript文件都不会更新 [英] JavaScript file not updating no matter what I do

查看:98
本文介绍了无论我做什么,JavaScript文件都不会更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个外部JavaScript文件,无论是在FireFox还是Chrome中,无论是否清除了所有浏览数据,它都不会更新。我认为某事是在备份文件时发生的,我只是在名称末尾添加了 _thedate。然后将另存为还原为原始名称。

I have an external JavaScript file and whether in FireFox or Chrome, whether all browsing data is cleared, it will NOT update no matter what. I believe something happened when I made a backup of my file, which I simply added "_thedate" to the end of the name. Then Save As back to the original name.

现在,除非更改文件名,否则无论如何我似乎都无法摆脱旧的JS。

Now I cannot seem to get rid of the old JS no matter what unless I change the name of the file, which I really don't want to do, or add the script to the PHP page, which crowds it.

任何人都知道解决方案吗?

Anyone know the solution to this?

推荐答案

您确定要链接到同一文件,然后编辑该文件吗?

You are sure you are linking to the same file and then editing that same file?

在某些浏览器上,您可以使用 CTRL F5 强制刷新(在PC上)。在Mac上,它是 Cmd Shift R

On some browser, you can use CTRL F5 to force a refresh (on the PC). On the Mac, it is Cmd Shift R

Firebug也有一个带有禁用浏览器缓存。

Firebug also has a net tab with "Disable Browser Cache".

但我想在此发出警告:即使可以硬刷新,您如何知道您的客户正在获得最新版本?因此,您需要检查,而不仅仅是确保您和您的程序经理可以进行一次彻底的刷新,然后回家下个月拿薪水。如果您想从事一项能够使世界变得更好的工作,或者让世界变得比您发现的更好,您需要进行更多调查以确保它也对您的客户有效(否则,有时客户可能呼叫技术支持,技术支持可能会读取清除cookie并起作用的脚本,这有时会发生在我身上。这篇文章底部的一些方法可以确保客户获得最新版本。

But I want to give a warning here: even if you can hard refresh, how do you know your customers are getting the latest version? So you need to check, rather than just making sure you and your program manager can do a hard refresh and just go home and take the paycheck next month. If you want to do a job that change the world for the better, or leave the world a little bit better than you found it, you need to investigate more to make sure it works for your customers too (or else, sometimes the customer may call tech support, and tech support may read the script of "clear out the cookies and it will work", which is what happens to me sometimes). Some methods down at the bottom of this post can ensure the customers get the latest version.

如果您使用的是Chrome和DevTools已打开,您可以单击并按住地址栏前面的Refresh图标,然后会弹出一个框,您可以选择硬重载。甚至空缓存和硬重载:

If you are using Chrome and the DevTools is open, you can click and hold the Refresh icon in front of the address bar, and a box will pop up, and you can choose to "Hard Reload" or even "Empty Cache and Hard Reload":

如果您使用的是Google Chrome调试器,则相同,可以转到网络部分并确保禁用缓存(打开DevTools时)。

If you use the Google Chrome debugger, it is the same, you can go to the Network section and make sure the "Disable cache (while DevTools is open)" is checked, in the Settings of the debugger panel.

此外,在链接JavaScript文件时,请使用

Also, when you link the JavaScript file, use

<script src="my-js-file.js?v=1"></script>

v = 2 ,依此类推,当您确定要刷新文件。或者,您可以转到控制台并执行 Date.now()并获取时间戳,例如 1491313943549 ,并使用

or v=2, and so forth, when you definitely want to refresh the file. Or you can go to the console and do a Date.now() and get a timestamp, such as 1491313943549, and use

<script src="my-js-file.js?t=1491313943549"></script>

某些构建工具会自动为您执行此操作,或者可以将其配置为执行此操作,使其类似于:

Some building tools will do that automatically for you, or can be configured to do that, making it something like:

<script src="main.742a4952.js"></script>

这实际上将破坏缓存。

注意当您使用 v = 2 t = 1491313943549 main.742a4952时.js ,您还拥有一个优势,即对于您的用户,他们肯定也会获得更新版本。

Note that when you use the v=2 or t=1491313943549, or main.742a4952.js, you also have the advantage that for your users, they definitely will get the newer version as well.

这篇关于无论我做什么,JavaScript文件都不会更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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