User tests: Successful: Unsuccessful:
Pull Request for comment #30444 (comment)
When the site runs in debug mode, then on every page load a new media version is added the the assets. This is problematic while debugging Javascript in a browser. Like that the browser always assumes that it is a new script and removes the breakpoints (at least this is the case in Firefox). If you do JS debugging, you know what I'm talking about ;-)
This behavior is a relict from the early days of Joomla (#1618) to simplify development. But nowadays every developer knows how to load the page with Ctrl+F5
to refetch the assets.
CC: @dgrammatiko, @ceford
Open any page in debug mode.
Open the dev tools of the browser and check the loaded JS and CSS files.
Assets are always loaded with a new media version after the path.
Assets are loaded without any media version.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
If devs are using correctly the Web Assets this shouldn't be a problem. Let me explain:
joomla.assets.json
files and calculate each asset's version based on the content. The hash/version is only changed if the dev re-executes the versioning script.I can't but just recommend every dev to endorse the web assets and also try to use, or at least be inspired by, the project's own tooling...
If devs are using correctly the Web Assets this shouldn't be a problem. Let me explain:
- Joomla's own tools (that also devs could use for their own code) has a versioning script: https://github.com/joomla/joomla-cms/blob/4.0-dev/build/build-modules-js/versioning.es6.js. This script will loop all the
joomla.assets.json
files and calculate each asset's version based on the content. The hash/version is only changed if the dev re-executes the versioning script.- Of course, HTMLHelper is the old guard and uses the media version that is updated per joomla update, so I guess this patch is covering that case.
I can't but just recommend every dev to endorse the web assets and also try to use, or at least be inspired by, the project's own tooling...
2 problems with this script.
I know that's not the way to do it but it's reality that this happens.
I would prefer to take do this update on include time when the file is requests (check modify date and content).
It's also not possible in the WA manager to set a special version for a file from the template.
something I liked in dev process to simply add a '?v='.rand() to all css und js assets.
Also I think in debug mode we should also set the "version" string to something less static (like the hash of the content)
sorry allon for the partly off-topic comment
@HLeithner I have to disagree on both problems
it only runs when I want it to run
The hash derives from the file content. It shouldn't change with some magic PHP functionality per call. So, for me this is the correct way
doesn't work if you have to debug a live/site on a customer server.
Actually, since PHP is totally unaware of the hash (is passed from the JSON file) you can debug the file as you're pleased. The hash WON'T change (unless you change it).
I would prefer to take do this update on include time when the file is requests (check modify date and content).
No, not in runtime, you're adding too much processing and I/O for something that can be way simpler. How simpler, something like: https://invalidate-cache.dgrammatiko.dev . What I mean is that the functionality of that module should be baked in into the template file editor or anywhere that a user could change the contents of a static file. In short, try to do as little as possible on runtime, precalculate and cache everything you can (at least that's my approach to anything server side)
I only talk of debug mode, not afterwards. Like a option/switch you can give the asset manager $wa->setDebug(true);
which magically disable caching (add cache busters).
of course I wouldn't do this in normal operation.
Like a option/switch you can give the asset manager $wa->setDebug(true);
The switch already exists, the JDEBUG
constant. Changing the logic to not append the media version if the JDEBUG == true
should be straight forward. That said wouldn't this change be simpler if this
joomla-cms/libraries/src/Document/Renderer/Html/ScriptsRenderer.php
Lines 186 to 190 in 92ae417
@dgrammatiko actually yes I think changeing the script renderer to use the JDEBUG constant would be better.
@laoneo what do you think?
With my approach you save a DB insert operation ;-)
When the site runs in debug mode, then on every page load a new media version is added the the assets.
I think it was made to be sure that hash will be new when you turn off debug (one of reasons).
Kind of hash reset thing
Labels |
Added:
?
|
As you can see in the original pr, this was not really the intention, more a side effect :-)
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-03-28 07:19:18 |
Closed_By | ⇒ | laoneo |
@phproberto maybe you want to leave feedback as you was the author of the initial pr.