Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cache key to assets #5003

Merged
merged 16 commits into from
Jan 12, 2022
Merged

Add cache key to assets #5003

merged 16 commits into from
Jan 12, 2022

Conversation

sculpt0r
Copy link
Contributor

@sculpt0r sculpt0r commented Dec 21, 2021

What is the purpose of this pull request?

Does your PR contain necessary tests?

All patches that change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.

This PR contains

  • Unit tests
  • Manual tests

Did you follow the CKEditor 4 code style guide?

Your code should follow the guidelines from the CKEditor 4 code style guide which helps keep the entire codebase consistent.

  • PR is consistent with the code style guide

What is the proposed changelog entry for this pull request?

* [#4761](https://github.com/ckeditor/ckeditor4/issues/4761): Add cacheKey (timestamp) to CSS assets loads via editor.

What changes did you make?

Give an overview…

The previous solution #4852 changed the default behavior for CSS URLs. Each time, the URL was provided - it was turned into the absolute path via the getUrl function which adds URL calculated based on CKEDITOR_BASEPATH.

getUrl: function( resource ) {
// If this is not a full or absolute path.
if ( resource.indexOf( ':/' ) == -1 && resource.indexOf( '/' ) !== 0 )
resource = this.basePath + resource;

However, it was not always valid for products that may serve CKE4 from a specific location. The user may still want to serve its own CSS files based on the path related to the loaded page, not the editor.

Please notice, that changes in ckeditor_base.js require additional action and lead to changes in ckeditor.js:

// Simply run `grunt ckeditor-base-replace` after changing this file.

I changed almost the same places, but only appends the cache key.

Also, added tests for getUrl from the previous solution. Since @Comandeer already spends time to cover this part of the editor with the test - we may use them.

Which issues does your PR resolve?

Closes #4761 .

@sculpt0r sculpt0r changed the title Add manual test. Add cache key to assets Dec 21, 2021
@sculpt0r sculpt0r marked this pull request as ready for review December 23, 2021 08:44
@github-actions
Copy link

It's been a while since we last heard from you. We are marking this pull request as stale due to inactivity. Please provide the requested feedback or the pull request will be closed after next 7 days.

@github-actions github-actions bot added the stale The issue / PR will be closed within the next 7 days of inactivity. label Dec 30, 2021
Copy link
Contributor

@KarolDawidziuk KarolDawidziuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @sculpt0r
Everything looks solid and works properly. 👍

There are some small typos to check and also I am thinking about creating an additional test. Please check my comments below.


<script>
( function() {
if ( bender.tools.env.mobile || !CKEDITOR.timestamp ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, this test will be only run on builded version of the editor.
Maybe should we create another test with sets CKEDITOR.timestamp, which will allow checking properly adding cache key without building the editor, WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be difficult to do so as timestamp should be set before resources are being loaded – so basically before loading CKEditor. As Bender manages loading the editor, it's a really non-trivial task

Copy link
Contributor Author

@sculpt0r sculpt0r Jan 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally speaking sounds like a good idea, but due to ⬆️ #5003 (comment) I'll leave it as it is.

},

// (#4761)
'test buidStyleHtml returns relative URL for passed relative URL string': function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'test buidStyleHtml returns relative URL for passed relative URL string': function() {
'test buildStyleHtml returns

The same typo is in the next 2 tests.

expected = '<style>' + styleText + '</style>',
styledStringElem = CKEDITOR.tools.buildStyleHtml( styleText );

assert.areSame( expected, styledStringElem, 'Styled text was not exact same wrapped in style elem' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert.areSame( expected, styledStringElem, 'Styled text was not exact same wrapped in style elem' );
assert.areSame( expected, styledStringElem, 'Styled text was not exact same wrapped in style element' );

@jacekbogdanski jacekbogdanski removed the stale The issue / PR will be closed within the next 7 days of inactivity. label Jan 3, 2022
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solution looks good, however some stylesheets are still missing a cache key after building docs, e.g.

Could you look into it?


<script>
( function() {
if ( bender.tools.env.mobile || !CKEDITOR.timestamp ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be difficult to do so as timestamp should be set before resources are being loaded – so basically before loading CKEditor. As Bender manages loading the editor, it's a really non-trivial task

@sculpt0r
Copy link
Contributor Author

sculpt0r commented Jan 5, 2022

Rebased on the newest master.

@sculpt0r
Copy link
Contributor Author

sculpt0r commented Jan 5, 2022

In my case:

http://localhost:9001/ckeditor4/4.17.1/examples/image2.html – tableselection,css,

image

http://localhost:9001/ckeditor4/4.17.1/examples/spreadsheets.html – balloontoolbar.css, default.css, dialog.css.

image

@Comandeer are you sure you have a freshly built doc version?

@Comandeer
Copy link
Member

Comandeer commented Jan 5, 2022

@Comandeer are you sure you have a freshly built doc version?

Yes. These were the only resources without the cache key, everything else had it 🤔 I'll check it once more.

@Comandeer
Copy link
Member

Ok, it works. It seems that something's wrong with our docs build system (see #5019) and I had to force proper CKE4 version by manually checking out the branch inside repos/ckeditor-presets/ckeditor.

Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solution looks good, I'm only missing direct tests for CKEDITOR.appendTimestamp().

@sculpt0r
Copy link
Contributor Author

sculpt0r commented Jan 7, 2022

Rebased on the newest master

@sculpt0r
Copy link
Contributor Author

@Comandeer - ready for another review.

  • added tests for appendNamespace

@Comandeer Comandeer self-assigned this Jan 11, 2022
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I've just slightly improved API docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache key not applied everywhere
4 participants