Skip to content

Commit

Permalink
Add cache key to css Url via
Browse files Browse the repository at this point in the history
  • Loading branch information
sculpt0r authored and Comandeer committed Jan 12, 2022
1 parent 03ab4c4 commit cc875e0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
3 changes: 3 additions & 0 deletions core/dom/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ CKEDITOR.tools.extend( CKEDITOR.dom.document.prototype, {
* @param {String} cssFileUrl The CSS file URL.
*/
appendStyleSheet: function( cssFileUrl ) {
var cacheKey = CKEDITOR.timestamp ? '?t=' + CKEDITOR.timestamp : '';
cssFileUrl += cacheKey;

if ( this.$.createStyleSheet )
this.$.createStyleSheet( cssFileUrl );
else {
Expand Down
28 changes: 24 additions & 4 deletions tests/core/dom/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,30 @@ bender.test( appendDomObjectTests(
var doc = new CKEDITOR.dom.document( document );
doc.appendStyleSheet( cssUrl );// this makes absolute URL no matter what is passed

var links = document.getElementsByTagName( 'link' );
var succeed = CKEDITOR.tools.array.some( links, function( link ) {
return link.href === cssUrl;
} );
var links = document.getElementsByTagName( 'link' ),
succeed = CKEDITOR.tools.array.some( links, function( link ) {
return link.href === cssUrl;
} );

CKEDITOR.timestamp = originalTimestamp;
assert.isTrue( succeed, 'The link element was not found' );
},

// (#4761)
'test appendStyleSheet with timestamp': function() {
var originalTimestamp = CKEDITOR.timestamp,
fakeTimestamp = 'cke4',
cssUrl = CKEDITOR.basePath + 'tests/_assets/sample.css',
expectedCssUrl = cssUrl + '?t=' + fakeTimestamp;

CKEDITOR.timestamp = fakeTimestamp;
var doc = new CKEDITOR.dom.document( document );
doc.appendStyleSheet( cssUrl );// this makes absolute URL no matter what is passed

var links = document.getElementsByTagName( 'link' ),
succeed = CKEDITOR.tools.array.some( links, function( link ) {
return link.href === expectedCssUrl;
} );

CKEDITOR.timestamp = originalTimestamp;
assert.isTrue( succeed, 'The link element was not found' );
Expand Down

0 comments on commit cc875e0

Please sign in to comment.