Force CKEDITOR to refresh config

耗尽温柔 提交于 2019-11-28 17:52:43

I have found a quite elegant way:

It is enough to set:

CKEDITOR.timestamp='ABCD';

just after you link ckeditor.js or anyhow before ckeditor loads all its files

this is the variable CKEDITOR uses to add timestamp to all .js .css files it loads dynamically.

So every time I change those files I update that variable and browsers will reload them.

Here's what I did to fix it. In your /ckeditor/config.js add this line:

CKEDITOR.timestamp = 'something_random'; 

Update "something_random" every time you have plugin updates.

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.

For me setting CKEDITOR.timestamp = +new Date works 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).

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.

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.

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.

You could always add a unique timestamp as a variable in your url, or just do a hard refresh (CTRL + F5)

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.

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.

Jawwad Ahmed

Add the following code to 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:rString in ckeditor.js.

izus

On Firefox:

  1. Go to about:config
  2. Set network.http.use-cache to false
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!