No Code Attached Yet
avatar hans2103
21 Aug 2020

Steps to reproduce the issue

View source on a clean J3 / J4 installation and you will see scripts and stylesheets in the head.
All css and js files are extended with a string of numbers and letters.
They are meant for cache invalidation... and it should work if they would change when the file is changed.
They don't change when the file is changed.

for example in J3

<link href="/templates/protostar/css/template.css?dacd9129dca0f2ae311fd26072498696" rel="stylesheet" />

This css file is set in templates/protostar/index.php line 41

// Add Stylesheets
JHtml::_('stylesheet', 'template.css', array('version' => 'auto', 'relative' => true));

The version = auto causes the extension of the filename
version = joomla-rocks will cause the following output

<link href="/templates/protostar/css/template.css?joomla-rocks" rel="stylesheet" />

The link elements are set in
The so-called $mediaversion comes from
It is an md5 hash of the long Joomla version together with the secret from configuration.php plus date.
The mediaversion will be set when not present or when the Joomla version changes or when in DEBUG mode.

In J4 the link element is set via
And uses the same $mediaversion from libraries/src/Version.php

It would be nice if this can be rewritten to something that looks at the filemtime of the loaded asset.

class TemplateHelper
     * Load CSS
    static public function loadCss()
        HTMLHelper::_('stylesheet', 'style.css', ['version' => self::getFileMTime(JPATH_THEMES . '/' . self::template(). '/css/style.css'), 'relative' => true]);

    static public function getFileMTime($file)
        if (!file_exists($file) || filesize($file) == 0)
            return null;

        return filemtime($file);

should the function getMediaVersion.php from libraries/src/version.php be rewritten?

Expected result

I am expecting that when I change a css / js file the version will change as well.

Actual result

When changing a css / js file in the template the version does not change... this causes me headache when certain css changes are not to be seen. :-)

System information (as much as possible)

Additional comments

avatar hans2103 hans2103 - open - 21 Aug 2020
avatar joomla-cms-bot joomla-cms-bot - change - 21 Aug 2020
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 21 Aug 2020
avatar brianteeman
brianteeman - comment - 22 Aug 2020

The string is joomla version based. When debug is enabled there are additional options. You would need to go back to the original PR and discussions to see the logic behind this choice

avatar hans2103
hans2103 - comment - 22 Aug 2020

Implemented in 2013 with #1618
The mediaversion is updated on Joomla Update, Extension Install, Extension Uninstall or DB Fix.
That's nice... but I think the mediaversion should be file dependent and needs an update when the file is modified.

avatar dgrammatiko
dgrammatiko - comment - 23 Aug 2020

@hans2103 the whole concept that Joomla is using for versioning the assets is TOTALLY WRONG.
Assets should only change their version ONLY if the contents of the file has changed. Right now (J3 or J4) Joomla INVALIDATES ALL THE STATIC ASSETS per new release. At least a stupid strategy (if anyone can even call this a strategy).
But to be fair here, J3 doesn't have the means for anything better, so invalidating all the assets per any update was the only possible solution.
J4 is in far better place, assets get compiled before packaging therefore it's as simple as injecting a "version": "some-unique-sting" in all the relative JSON files (used by the new asset manager).

To cut it short I have demonstrated how this can be done eg:

My 2c

avatar brianteeman
brianteeman - comment - 23 Aug 2020

that is zero help for when the user edits the css in the template manager

avatar dgrammatiko
dgrammatiko - comment - 23 Aug 2020

that is zero help for when the user edits the css in the template manager

Actually it just needs a little more effort on the model of com_templates so whenever an asset is changes also the relevant json version is updated. Definitely doable, also the whole concept of the new asset manager is that: Joomla should be doing as less I/O (file reads) processing as possible, thus the json file that acts as storage for all the possible needed attributes.

avatar brianteeman
brianteeman - comment - 23 Aug 2020

when you've built that you can say the current method is wrong

avatar dgrammatiko
dgrammatiko - comment - 23 Aug 2020

when you've built that you can say the current method is wrong

I did and I posted the relevant links. I don't need the com_templates functionality so that wasn't on my list...

avatar ceford
ceford - comment - 15 Oct 2020

I wanted to have a look at the javascript with the browser debug tools - spent all day trying to figure out what was wrong. So in debug mode the version string is changed on every page load, whether or not any css or js file has changed. That means any js file of interest is removed from the debugger along with its breakpoints. So you have to set the break points again and you cant debug initialisation sequences. In the end I found this bug report and just went to libraries/src/Version.php and removed JDEBU || from line 256.

My problem is that, in media/templates/atum/js/template.js, I don't know enough to understand what this means:

(function (Joomla, doc) {
})(window.Joomla, document);

The ... in between I can follow. Can anyone point me to an explanation?

This comment was created with the J!Tracker Application at

Add a Comment

Login with GitHub to post a comment