Matthias Bathke Avatar

from

Reading time: 6 minutes

Performance boost: Hide ACF scripts & CSS

Advanced Custom Fields (ACF) is a significant tool for WordPress developers. It enables the creation of customized input masks and the integration of these fields directly in the frontend. But despite its capabilities, it brings a small flaw: The deterioration of PageSpeed due to mostly unnecessary scripts in the frontend.

The problem in detail

When using ACF to add form fields in the frontend, such as for user comments, the following happens:

  • All form scripts are loaded, without on-demand loading.
  • Dependencies on frameworks like jQuery and jQueryUI arise, leading to more reloaded scripts.
  • There may be incompatibilities and unexpected behavior, as some scripts are optimized for the WP admin and thus may cause conflicts with other themes or plugins.
  • The main problem: the significant degradation of PageSpeed, which is a critical factor for search engine optimization.

Common mistake with a big impact

Advanced Custom Fields is far from the only plugin that faces such difficulties. WooCommerce, for example, presents similar bloopers and significantly increases page load time, especially for shopping cart and checkout. It is therefore essential for website operators to always evaluate the consequences of a plugin and its respective functions.

The effective solution

Numerous WP admin scripts are outputted unnecessarily in the frontend.

Advanced Custom Fields offers an official solution for this so far, let alone a filter.

To suppress the automatic loading of ACF scripts in the frontend, you can add the following code to your theme’s functions.php or use it as a standalone plugin:

<?php
if(!is_admin()){
    add_action('acf/init', function(){
        acf_update_setting('has_done_ACF_Assets::add_actions', true);
    });
}Code language: HTML, XML (xml)

The solution described here tricks Advanced Custom Fields into thinking that scripts loading has already been performed in the frontend – not an official way, but it suffices as a hotfix.

result

ACF has enormous potential and, if used correctly, can significantly increase the value of a web project. It is unfortunate that such successful plugin providers do not consider PageSpeed enough. A more conscious approach to this issue on the part of ACF would be a welcome improvement for all users.