如何停止 IE 中缓存 js 文件?

发布于 2024-09-03 04:04:07 字数 949 浏览 5 评论 0 原文

我创建了一个使用 CKEditor javascript 富编辑控件的页面。

这是一个非常简洁的控件,特别是因为它是免费的,但我对它允许添加模板的方式遇到了严重的问题。

要添加模板,您需要修改 CKEditor templates 文件夹中的 templates js 文件。描述它的文档页面位于此处

在我想要更新模板或添加新模板(或任何其他需要我修改 js 文件的内容)之前,这一切都很好。

Internet Explorer 会缓存 js 文件并且不会获取更新。清空缓存可以获取更新,但这不是可接受的解决方案。每当我更新模板时,我不想告诉组织中的所有用户清空他们的 IE 缓存。一定有更好的办法!

有没有办法阻止 IE 缓存 js 文件?或者这个问题还有其他解决方案吗?

更新

好的,我找到了这个部分< /a> 在 CKEditor API 中,这将允许我使用几个人建议的“在 url 中插入时间戳”解决方案。

所以脚本现在看起来像这样:

config.templates_files =
[
    '/editor_templates/site_default.js?time=' + utcTimeMilliseconds
];

谢谢你们的帮助。

I've created a page that uses the CKEditor javascript rich edit control.

It's a pretty neat control, especially seeing as it's free, but I'm having serious issues with the way it allows you to add templates.

To add a template you need to modify the templates js file in the CKEditor templates folder. The documentation page describing it is here.

This works fine until I want to update a template or add a new one (or anything else that requires me to modify the js file).

Internet Explorer caches the js file and doesn't pick up the update. Emptying the cache allows the update to be picked up, but this isn't an acceptable solution. Whenever I update a template I do not want to tell all of the users across the organisation to empty their IE cache. There must be a better way!

Is there a way to stop IE caching the js file? Or is there another solution to this problem?

Update

Ok, I found this section in the CKEditor API that will allow me to use the "insert timestamp into the url" solution suggested by several people.

So the script now looks like this:

config.templates_files =
[
    '/editor_templates/site_default.js?time=' + utcTimeMilliseconds
];

Thanks for your help guys.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

千纸鹤带着心事 2024-09-10 04:04:07

您可以将 rand 种子添加到 js 文件中。我的意思是

更新:

据我了解,你必须这样写 config.templates_files = [ '/mytemplates.js?seed=12345' ];

You can add rand seed to your js file. I mean <script src='jsFile.js?seed=12345'
And every time you want to empty cache - change seed number

Update:

as I understood you have to write like this config.templates_files = [ '/mytemplates.js?seed=12345' ];

一页 2024-09-10 04:04:07

您可以在包含 .js 文件时添加时间戳查询参数。

因此,不要使用 您可以

这应该使文件始终重新加载(时间戳需要是动态的并且随着页面的每次加载而变化..

Youo can add a timestamp query parameter when you include your .js file..

so instead of <script type="text/javascript" src="somefile.js"></script> you can <script type="text/javascript" src="somefile.js?timestampgoeshere"></script>

this should make the file to always get reloaded (the timestamp needs to be dynamic and changing for each load of the page..)

转身泪倾城 2024-09-10 04:04:07

恐怕您必须侵入 FCKEditor 代码并强制客户端 JavaScript 加载 XML 文件的新副本。您可以通过将 ?random=<随机数> 附加到所请求的 XML 文件的 URL 来实现此目的。 FCKEditor 是开源的,因此您应该能够找到请求 XML 的行并进行相应的修改。

I am afraid you'll have to hack into the FCKEditor code and force the client JavaScript to load fresh copy of the XML file. You can do so by appending a ?random=<a random number> to the URL of the XML file being requested. FCKEditor is opensource so you should be able to locate the lines the request the XML and modify accordingly.

司马昭之心 2024-09-10 04:04:07

相应地设置 Expires-Header,例如在 Apache 中。

ExpiresActive On
ExpiresByType text/javascript access

这不建议用于真正的 Web 应用程序,仅适用于 Intranet 场景,因为文件不可缓存。

Set Expires-Header accordingly, e.g. in Apache

ExpiresActive On
ExpiresByType text/javascript access

This is not recommended for a real web application, only for intranet scenarios because the files will not be cachable.

喜爱皱眉﹌ 2024-09-10 04:04:07

每次加载js文件时,传递一个随机数的变量作为变量。

src='/libs/js/myfile.js?4859487594573

ajax 加载文件的技巧相同。

every time you load the js file, pass a variable of a random number as a variable.

src='/libs/js/myfile.js?4859487594573

same trick for ajax loaded files.

再可℃爱ぅ一点好了 2024-09-10 04:04:07

多种方法(不需要全部执行):

  1. 按 ^F5 (control + F5) - 这将在没有缓存的情况下加载 发送
  2. 时设置杂注/缓存标头
  3. 在 GET 查询字符串中使用随机变量

Multiple methods (don't need to do them all):

  1. press ^F5 (control + F5) - that'll load without cache
  2. set pragma/cache headers on sending
  3. use a random variable in the GET query string
稚气少女 2024-09-10 04:04:07

.NET / C# :

public static void DisallowBrowserCache( )
{
    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    HttpContext.Current.Response.Cache.SetAllowResponseInBrowserHistory(false);
}

您可以让 ASP.NET 将 js 文件写入输出流 (http://server.com /jsFile.aspx,设置http headers),并通过上述方法控制响应的缓存行为。

.NET / C# :

public static void DisallowBrowserCache( )
{
    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    HttpContext.Current.Response.Cache.SetAllowResponseInBrowserHistory(false);
}

You could make ASP.NET write a js file to the outputstream (http://server.com/jsFile.aspx, set http headers), and control the caching behavior of the response with the above method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文