Description
I was working on #6555 and was trying to figure out why changes I was adding to the ckeditor5.admin.js
file would not take. Clearing caches would not solve it, so it left me head-scratching and wondering what I might be doing wrong. There was quite a waste of time before I finally discovered what was happening...
Updating other .js files in other parts of the admin UI where other modules are adding summary text to vertical tabs was working as expected, and changes would take straight away or after a simple cache clear. So this was clearly happening with ckeditor-related .js files. Inspecting the various .js assets loaded, I noticed that those that worked as expected had their query string set to a random token (coming from css_js_query_string
- see _backdrop_flush_css_js()
). The various ckeditor5-related .js assets on the other hand had v=1.29.x-dev
as their query string. That was effectively causing the files to be cached "persistently", and that explained why my changes wouldn't take ...despite clearing caches etc. I then tried Re-enabling JS aggregation, and that would indeed resolve the problem (because these files were not loaded as stand-alone assets any longer, so they didn't have the "fixed", version-based query string that caused the persistent caching).
I've tested locally, and there are a couple of ways to work around this:
- changing the logic in
backdrop_pre_render_scripts()
so that a random token is also added to the version-based query string of .js assets - removing the
'version' => $info['version']
from custom (Backdrop-specific, non-3rd-party) .js inckeditor5_library_info()
Noting that this problem doesn't apply to .css assets, as there is no logic currently in backdrop_pre_render_styles()
to be adding the 'version'
string as a query string.
So the above, along with time wasted trying to figure out things has got me thinking: who does this problem affect...
- Non-developer, end users (people that will never need to touch the .js code in their Backdrop sites): this group of people will not be affected.
- They have JS aggregation enabled. So all good 👍🏼
- When they update their site, the version string that is added as a query string to .js assets loaded gets updated to reflect the new version of Backdrop. So any persistently-cached .js file is cache-busted. This is the intended functionality. So all good 👍🏼
- Developers and especially core contributors: Chances are that these people disable their JS aggregation on their locals while working with code. That causes this problem here and, unless they know what's causing it and how to work around it, it will cause them grief/frustration and waste of time. DX 👎🏼
It also got me thinking: I know why we are adding the version string to the asset query (more effective/efficient caching), but when should it be added? As it is currently, if you omit it from your hook_library_info()
implementation, you get Warning: Undefined array key "version" in backdrop_get_library()
PHP errors. That means that developers will always try to add it. And when they wonder "what version should I use for this string?" ...the obvious thought would be either BACKDROP_VERSION
, or in the case of modules like CKEditor 5, the same version as the 3rd-party library. This is wrong though: "fixing" the version of .js assets to the version of core when developing locally will cause the query string to always be something like ?v=1.29.x-dev
, and that will cause them the issue described here. It does make sense to be adding the version string to the actual 3rd party libraries (files like core/modules/ckeditor5/lib/ckeditor5/build/ckeditor5-dll.js
or core/misc/smartmenus/jquery.smartmenus.js
or the various core/misc/jquery*.js
files etc.), but we should be discouraging people from adding it to the custom .js that we use in the admin UI, like core/modules/ckeditor5/js/ckeditor5.admin.js
. Right?
If we want to be adding the same version sting to those custom .js assets as the 3rd party library they are related to (as a way of "bundling them"), then can we at least offer another Do not add the version to the query string of JS assets
option in admin/config/development/performance
? That way, we allow developers/contributors to enable that option in their locals, and they won't be wasting the time I wasted trying to figure out why their code doesn't work.
Another thought I had: are the .js and .css files added by ckeditor5_library_info()
implementation an oversight? Were they left there after moving the module from contrib to core perhaps? Should they instead be loaded via #attached
or backdrop_add_js()
or some other way as needed? ...or is this a more generic problem? ...in which case we should also update the docblock of hook_library_info()
to warn people of the potential caching issues that might be caused by "fixing" 'version'
to a specific string?
Thoughts?