No Code Attached Yet bug
avatar tassosm
tassosm
7 Aug 2025

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.

My question

Is Joomla still rendering the field’s layout even when the field isn’t going to be displayed?

If yes:

  • Is this considered expected behavior, or is it a bug?
  • What’s the recommended way to load a field’s CSS/JS only when the field is actually rendered?

Additional context

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:

  • I modified its layout to load a dummy CSS file.
  • I set the field’s Automatic Display option to “Do not automatically display”.
  • I confirmed that the field does not appear on the frontend — but the CSS file was still injected into the DOM.

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?

avatar tassosm tassosm - open - 7 Aug 2025
avatar joomla-cms-bot joomla-cms-bot - change - 7 Aug 2025
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 7 Aug 2025
avatar Fedik
Fedik - comment - 7 Aug 2025

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:

$fields = FieldsHelper::getFields($context, $item, true);

The logic of this method need to be changed in a way that the "Content - Fields" plugin renders only needed fields.

avatar Fedik Fedik - change - 7 Aug 2025
Labels Added: bug
avatar Fedik Fedik - labeled - 7 Aug 2025
avatar tassosm
tassosm - comment - 7 Aug 2025

I believe it's unrelated to the Content Fields plugin, as it happens even if it's disabled.

Image
avatar Fedik
Fedik - comment - 7 Aug 2025

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.

if ($prepareValue && (\is_bool($prepareValue) || $prepareValue === (int) $field->params->get('display', '2'))) {

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.

avatar coolcat-creations
coolcat-creations - comment - 7 Aug 2025

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?

avatar Fedik
Fedik - comment - 7 Aug 2025

Nope sorry.
I have no fix currently. It is need to investigate more.
If someone know the fix, please make a PR.

avatar coolcat-creations
coolcat-creations - comment - 8 Aug 2025

@laoneo ? Maybe

Add a Comment

Login with GitHub to post a comment