User tests: Successful: Unsuccessful:
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.
Modify the version attribute in your joomla.asset.json to "nocache".
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
| Status | New | ⇒ | Pending |
| Category | ⇒ | Libraries |
Just wondering if this is not already solved by passing a random string as version option?
That's not possible in a json file.
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.
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()).
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?
| Labels |
Added:
PR-6.1-dev
|
||
We already have this feature. Enable Debug and you will get version refresh for every
autoitem. 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 everyautoitem 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.
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
joomla-cms/build/media_source/system/joomla.asset.json
Lines 8 to 13 in 7bd2c5b
I am not against it, if people want it then we can add.
I just don't see a reason for this.
Hm, I not very understand your use case. The
autois doing the same (when debug On), that probably why we have it. This makesnocache"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.
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.
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.
obviously this needs documentation please
Of course, we will see if I can do it or someone else needs to create it.
Just wondering if this is not already solved by passing a random string as version option?