? Pending

User tests: Successful: Unsuccessful:

avatar laoneo
laoneo
12 Nov 2021

Pull Request for comment #30444 (comment)

Summary of Changes

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

Testing Instructions

Open any page in debug mode.
Open the dev tools of the browser and check the loaded JS and CSS files.

Actual result BEFORE applying this Pull Request

Assets are always loaded with a new media version after the path.

Expected result AFTER applying this Pull Request

Assets are loaded without any media version.

avatar laoneo laoneo - open - 12 Nov 2021
avatar laoneo laoneo - change - 12 Nov 2021
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 12 Nov 2021
Category Libraries
avatar laoneo
laoneo - comment - 12 Nov 2021

@phproberto maybe you want to leave feedback as you was the author of the initial pr.

avatar dgrammatiko
dgrammatiko - comment - 12 Nov 2021

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...

avatar HLeithner
HLeithner - comment - 12 Nov 2021

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.

  1. it only runs when I want it to run
  2. doesn't work if you have to debug a live/site on a customer server.

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

avatar dgrammatiko
dgrammatiko - comment - 12 Nov 2021

@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)

avatar HLeithner
HLeithner - comment - 12 Nov 2021

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.

avatar dgrammatiko
dgrammatiko - comment - 12 Nov 2021

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

// Check if script uses media version.
if ($version && strpos($src, '?') === false && ($mediaVersion || $version !== 'auto'))
{
$src .= '?' . ($version === 'auto' ? $mediaVersion : $version);
}
was altered?

avatar laoneo laoneo - change - 12 Nov 2021
The description was changed
avatar laoneo laoneo - edited - 12 Nov 2021
avatar HLeithner
HLeithner - comment - 12 Nov 2021

@dgrammatiko actually yes I think changeing the script renderer to use the JDEBUG constant would be better.
@laoneo what do you think?

avatar laoneo
laoneo - comment - 12 Nov 2021

With my approach you save a DB insert operation ;-)

avatar Fedik
Fedik - comment - 12 Nov 2021

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

avatar laoneo laoneo - change - 15 Nov 2021
Labels Added: ?
avatar laoneo
laoneo - comment - 15 Nov 2021

As you can see in the original pr, this was not really the intention, more a side effect :-)

avatar laoneo
laoneo - comment - 17 Nov 2021

@Quy good spot

avatar laoneo laoneo - change - 28 Mar 2022
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2022-03-28 07:19:18
Closed_By laoneo
avatar laoneo laoneo - close - 28 Mar 2022

Add a Comment

Login with GitHub to post a comment