How do I stop js files being cached in IE?

2019-07-18 01:50发布

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条回答
手持菜刀,她持情操
2楼-- · 2019-07-18 02:54

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.

查看更多
登录 后发表回答