我创建了一个使用 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.
发布评论
评论(7)
您可以将 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' ];
您可以在包含 .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..)
恐怕您必须侵入 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.相应地设置 Expires-Header,例如在 Apache 中。
这不建议用于真正的 Web 应用程序,仅适用于 Intranet 场景,因为文件不可缓存。
Set Expires-Header accordingly, e.g. in Apache
This is not recommended for a real web application, only for intranet scenarios because the files will not be cachable.
每次加载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.
多种方法(不需要全部执行):
Multiple methods (don't need to do them all):
.NET / C# :
您可以让 ASP.NET 将 js 文件写入输出流 (http://server.com /jsFile.aspx,设置http headers),并通过上述方法控制响应的缓存行为。
.NET / C# :
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.