Javascript 强制 CKEDITOR 刷新配置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14940452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Force CKEDITOR to refresh config
提问by giammin
I created a cms application that use CKEDITOR and when I add some functionality to CKEDITOR I need to refresh some CKEDITOR .js /.css file.
我创建了一个使用 CKEDITOR 的 cms 应用程序,当我向 CKEDITOR 添加一些功能时,我需要刷新一些 CKEDITOR .js / .css 文件。
But CKEDITOR force the browser to cache them.
但是 CKEDITOR 强制浏览器缓存它们。
I see that it uses a querystring to all .js/.css files
我看到它对所有 .js/.css 文件使用查询字符串
This querystring reflect the CKEDITOR version I suppose:
这个查询字符串反映了我想的 CKEDITOR 版本:
/Js/ckeditor/config.js?t=CAPD
/Js/ckeditor/lang/it.js?t=CAPD
/Js/ckeditor/plugins/onchange/plugin.js?t=CAPD
Is there an embedded method to do that in CKEDITOR?
在 CKEDITOR 中是否有嵌入式方法可以做到这一点?
I could not find anything in the documentation. I'm using CKEDITOR 4
我在文档中找不到任何内容。我正在使用 CKEDITOR 4
The main problem is that when I upload some changes they are not updated by the clients and new functionality are not available or worst case CKEDITOR does not work.
主要问题是,当我上传一些更改时,客户端不会更新它们,并且新功能不可用,或者在最坏的情况下 CKEDITOR 不起作用。
回答by giammin
I have found a quite elegant way:
我找到了一个非常优雅的方式:
It is enough to set:
设置以下就足够了:
CKEDITOR.timestamp='ABCD';
just after you link ckeditor.jsor anyhow before ckeditor loads all its files
就在您链接 ckeditor.js 之后或无论如何在 ckeditor 加载其所有文件之前
this is the variable CKEDITOR uses to add timestamp to all .js .css files it loads dynamically.
这是 CKEDITOR 用来向它动态加载的所有 .js .css 文件添加时间戳的变量。
So every time I change those files I update that variable and browsers will reload them.
因此,每次更改这些文件时,我都会更新该变量,浏览器将重新加载它们。
回答by Alfred Armstrong
I found a much simpler method, in case anyone is still frustrated by this.
我找到了一个更简单的方法,以防有人仍然对此感到沮丧。
If you open the config file URL with the timestamp appended (eg. ?t=XYZD) in your browser, hard-refresh it, then return to your application page and refresh that, you should get the new version of the config file.
如果您在浏览器中打开附加了时间戳的配置文件 URL(例如 ?t=XYZD),对其进行硬刷新,然后返回到您的应用程序页面并刷新它,您应该会获得新版本的配置文件。
You need to use the same timestamp as is set by ckeditor in the source of the page. If you use developer tools or Firebug, typing CKEDITOR.timestamp into the console will give you the value to use.
您需要使用与 ckeditor 在页面源中设置的时间戳相同的时间戳。如果您使用开发人员工具或 Firebug,在控制台中输入 CKEDITOR.timestamp 将为您提供要使用的值。
回答by palmej2
Here's what I did to fix it. In your /ckeditor/config.js add this line:
这是我为修复它所做的。在你的 /ckeditor/config.js 添加这一行:
CKEDITOR.timestamp = 'something_random';
Update "something_random" every time you have plugin updates.
每次有插件更新时更新“something_random”。
In your page that uses it, make sure and load the resources like this:
在使用它的页面中,确保并加载这样的资源:
<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
<script src="/ckeditor/config.js?v=something_random"></script>
By doing this the config.js will get loaded twice because CKEditor will load it on it's own however it will still work fine, and this should give you the control you need to get an automatic refresh on all browsers. I am a .NET developer, and actually put the /ckeditor/config.js in my bundler, so it gets the version on the querystring automatically, but if you aren't using a fancy bundler, just do what I said above manually with the ?v=something_random.
通过这样做,config.js 将被加载两次,因为 CKEditor 会自行加载它,但它仍然可以正常工作,这应该为您提供在所有浏览器上自动刷新所需的控制权。我是 .NET 开发人员,实际上将 /ckeditor/config.js 放在我的捆绑器中,因此它会自动获取查询字符串上的版本,但是如果您不使用精美的捆绑器,只需手动执行我上面所说的?v=something_random。
回答by leymannx
For me setting CKEDITOR.timestamp = +new Dateworks super fine. I wrote it in a JS that will be loaded before any other CKEditor JS will be loaded (see my custom Drupal module).
对我来说,设置CKEDITOR.timestamp = +new Date工作得非常好。我用 JS 编写它,该 JS 将在加载任何其他 CKEditor JS 之前加载(请参阅我的自定义 Drupal 模块)。
Now the query that is appended to the custom plugin or custom config JS gets refreshed every time I reload my browser. I guess that might work with custom CSS as well, but I didn't test that.
现在,每次我重新加载浏览器时,附加到自定义插件或自定义配置 JS 的查询都会刷新。我想这也可能适用于自定义 CSS,但我没有测试过。
回答by Jawwad Ahmed
Add the following code to ckeditor.js
将以下代码添加到 ckeditor.js
/*Lets Create a random number*/
function randomString(length, chars) {
var result = '';
for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
return result;
}
var rString = randomString(4, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
After that substitute the value timestamp:rStringin ckeditor.js.
之后替换timestamp:rStringckeditor.js 中的值。
回答by Kidquick
This trick works in Firefox for not just CKEditor but for any page on which you want to toggle local caching.
这个技巧在 Firefox 中不仅适用于 CKEditor,而且适用于您想要切换本地缓存的任何页面。
- Open Firefox debugging console (F12).
- Open console settings (F1).
- Enable "Disable HTTP Cache (when toolbox is open)".
- Keep console open :)
- 打开 Firefox 调试控制台 (F12)。
- 打开控制台设置 (F1)。
- 启用“禁用 HTTP 缓存(工具箱打开时)”。
- 保持控制台打开:)
After a very brief check, I could not find a similar setting in Chrome nor IE.
经过非常简短的检查,我在 Chrome 和 IE 中都找不到类似的设置。
HTH
HTH
回答by wloges
Method wich works is put CKEDITOR with improved config and css files to the new subcatalog:
有效的方法是将带有改进配置和 css 文件的 CKEDITOR 放到新的子目录中:
src="/ckeditor_new_one/ckeditor.js"
src="/ckeditor_new_one/ckeditor.js"
回答by Bas Tuijnman
You could always add a unique timestamp as a variable in your url, or just do a hard refresh (CTRL + F5)
你总是可以在你的 url 中添加一个唯一的时间戳作为变量,或者只是硬刷新 (CTRL + F5)
回答by Nick Zinger
The timestamp solution didn't work for me so in case anyone else has the same issue, I appended ?v=date to where I'm including ckeditor.js, and then again inside ckeditor.js where config.js is referenced.
时间戳解决方案对我不起作用,所以如果其他人有同样的问题,我将 ?v=date 添加到我包含 ckeditor.js 的位置,然后再次在 ckeditor.js 中引用 config.js。
It seems that since config.js is being cached, the new timestamp doesn't get used. At least not until after a few refreshes, but that's not something I can tell my users to do.
似乎因为 config.js 被缓存,新的时间戳没有被使用。至少要在几次刷新之后才能做到,但这不是我可以告诉我的用户做的事情。
回答by izus
On Firefox:
在 Firefox 上:
- Go to
about:config - Set
network.http.use-cachetofalse
- 去
about:config - 设置
network.http.use-cache为false

