PR-6.1-dev Pending

User tests: Successful: Unsuccessful:

avatar HLeithner
HLeithner
29 Oct 2025

Summary of Changes

Add the magic value "nocache" similar to "auto" to the joomla.asset.json renderer for scripts and styles.
This allows to add a js and css file already to the asset file while developing without struggling with all the possible cache layers.
Additional, it's possible that you need a cache buster for resources which are not under your control and changes frequently or are dynamically generated with a broken cache header.

Testing Instructions

Modify the version attribute in your joomla.asset.json to "nocache".

Actual result BEFORE applying this Pull Request

  • request url: media/com_xyz/js/your.js?nocache

Expected result AFTER applying this Pull Request

  • request url: media/com_xyz/js/your.js?nocache-<RANDOM NUMBER BETWEEN 0 AND 1.000.000>

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org: Will be added when excepted

  • No documentation changes for manual.joomla.org needed

avatar HLeithner HLeithner - open - 29 Oct 2025
avatar HLeithner HLeithner - change - 29 Oct 2025
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 29 Oct 2025
Category Libraries
avatar laoneo
laoneo - comment - 30 Oct 2025

Just wondering if this is not already solved by passing a random string as version option?

avatar HLeithner
HLeithner - comment - 30 Oct 2025

Just wondering if this is not already solved by passing a random string as version option?

That's not possible in a json file.

avatar laoneo
laoneo - comment - 30 Oct 2025

Sure, but I would then probably use the existing version attribute and support there a "nocache" value instead of adding a new flag. But this is just personal preference.

avatar Fedik
Fedik - comment - 30 Oct 2025

We already have this feature. Enable Debug and you will get version refresh for every auto item.
I do not think we need another magic string here.

It is also possible just call $doc->setMediaVersion(time()) in the layout (will work for every auto item without enabling debug).
Or we could fix $wa->getAsset(....)->setOption('version', time()).

avatar HLeithner
HLeithner - comment - 30 Oct 2025

Sure, but I would then probably use the existing version attribute and support there a "nocache" value instead of adding a new flag. But this is just personal preference.

I'm not sure to understand you? I set the existing "version" attribute to "nocache" similar to "auto" and not adda new attribute?

avatar HLeithner HLeithner - change - 30 Oct 2025
Labels Added: PR-6.1-dev
avatar HLeithner
HLeithner - comment - 30 Oct 2025

We already have this feature. Enable Debug and you will get version refresh for every auto item. I do not think we need another magic string here.

It is also possible just call $doc->setMediaVersion(time()) in the layout (will work for every auto item without enabling debug). Or we could fix $wa->getAsset(....)->setOption('version', time()).

I want to do something different, I don't want to set it manually on each layout I'm using it and and want to have this persistent if I need to by path cache for what ever reason. (3rd party services for example).

setMediaVersion() would effect all script and styles which has a negative performance impact, setting it to the option would mean I have to add this to each usage which is error prone.

avatar Fedik
Fedik - comment - 30 Oct 2025

Hm, I not very understand your use case.
The auto is doing the same (when debug On), that probably why we have it.
This makes nocache "duplicate feature" basically (to me).

If you want to have some "custom generated" version only for specific asset and do not want to use setOption() in each layout then can also create a custom class:

{
    "name": "myasset",
    "type": "script",
    "class": "MyAssetItem",
    "namespace": "Foo\\Bar"
    "uri": "....myasset.js"
},
class MyAssetItem extends WebAssetItem 
{
  public function __construct(
        string $name,
        ?string $uri = null,
        array $options = [],
        array $attributes = [],
        array $dependencies = []
  ) {
      parent::__construct($name, $uri, $options, $attributes, $dependencies);

      $this->version = ComponentHelper::getParams('com_mycomponent')->get('myMediaVersion', '');
   }
}

Similar to core

{
"name": "core",
"type": "script",
"class": "CoreAssetItem",
"uri": "system/core.min.js"
},

avatar Fedik
Fedik - comment - 30 Oct 2025

I am not against it, if people want it then we can add.
I just don't see a reason for this.

avatar HLeithner
HLeithner - comment - 30 Oct 2025

Hm, I not very understand your use case. The auto is doing the same (when debug On), that probably why we have it. This makes nocache "duplicate feature" basically (to me).

I want to make developer life easier, I don't want to create a new WebAsset if I just don't want no caching for exactly one script for a temporary time.
I want to make developer life easier, I don't want to create a new WebAsset if I need a cache buster for a (remote) resource I include.

Of course we can add an additional webassetitem in core that does this, but that sounds a bit overengineered compared to the the 2 lines of code change.

avatar Fedik
Fedik - comment - 30 Oct 2025

When I need it I usually just enable debug and disable debug plugin to hide the debug bar.

With nocache you getting a risk to forget to remove it, and push it to production.

avatar bembelimen bembelimen - test_item - 30 Oct 2025 - Tested successfully
avatar bembelimen
bembelimen - comment - 30 Oct 2025

I have tested this item ✅ successfully on 53614f1

I see this a sensible addition for developers. It saves me the time to update on every JS/CSS change the version attribute and especially when I have to check something on a live site, I don't want to enable debug mode at all. I appreciate, there is a risk of forgetting the attribute, but same could happen with debug mode etc.

So I'm in favour of this change.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46379.

avatar brianteeman
brianteeman - comment - 31 Oct 2025

obviously this needs documentation please

avatar HLeithner
HLeithner - comment - 31 Oct 2025

Of course, we will see if I can do it or someone else needs to create it.

Add a Comment

Login with GitHub to post a comment