I have a custom field assigned to an article, with the “Automatic Display” option set to “Do not automatically display”. The article does not include a {field.xxx} shortcode either.
So, in this case, the field is not rendered on the frontend — as expected.
However, if the field layout (tmpl/myfield.php) includes asset loading (CSS or JS), those assets are still loaded into the DOM.
Is Joomla still rendering the field’s layout even when the field isn’t going to be displayed?
If yes:
This happens consistently across all custom fields I’m offering through my Advanced Custom Fields extension.
To rule out issues in my implementation, I also ran a test using Joomla’s core Text field:
This suggests Joomla calls the layout even when the field isn’t going to be displayed.
Is there a clean or official way to detect whether the field will be actually rendered, so that assets are only loaded when necessary?
Labels |
Added:
No Code Attached Yet
|
Labels |
Added:
bug
|
Second call of FieldsHelper::getFields($context, $item, true)
is in System - Fields.
However by looking more I do not see "Do not automatically display" option is preventing anything.
At least I did not found.
This section is calling onCustomFieldsPrepareField
which rendering the field layout.
And as long as $prepareValue
is true
the field will be rendered, and so its assets will be attached.
I have this issue on my website, it's decreasing the performance by loading unnecessary scripts. I hope there is an easy fix for that?
Nope sorry.
I have no fix currently. It is need to investigate more.
If someone know the fix, please make a PR.
It sounds like a bug in "Content - Fields" plugin, which trying to render ALL fields for given article before actually checking what field need to be shown:
joomla-cms/plugins/content/fields/src/Extension/Fields.php
Line 120 in 552ee57
The logic of this method need to be changed in a way that the "Content - Fields" plugin renders only needed fields.