Home Forums Front-end Issues Remove unused scripts/styles


Remove unused scripts/styles

  • Hello everyone!

    I realized that I don’t need most of the code loaded in the frontend- actually not in the backend either – eg select2, datepicker, timepicker, etc

    Additionally, although I am using the Repeater component, I don’t use the sortable feature in the frontend only; I realize that this is a tough one because it might be required to load the component. It would be really great to implement such features on-demand although I guess the devs would focus on other, more important things first.

    So, the question is, can you deregister and/or dequeue scripts/styles that are not used?

  • Any individual script or style sheet can be removed using and The trick is finding the right handle and the right time to remove them. For acf I would try the acf/admin_enqueue_scripts hook with a high priority. However, you may see unintended side effects since a lot of ACF depends on these 3rd party scripts and styles.

  • Well, I realized that much, I was looking for specifics – something like a list of the styles and scripts used.

    I understand for example, that ACF itself uses the select2 plugin in the admin in several cases, but I don’t get why this is loaded through the acf_form_head function in the frontend – in an ideal workflow, the plugin would somehow manage to see which field types are used and load the necessary scripts. On top of that having additional options on ‘heavy’ components – like the Repeater – to toggle on/off features not required, eg the sortable function or remove the tooltips.

    ..since this is not the case, I am willing to try by the good’ol’ trial-and-error method to see what works and what breaks in my frontend.

    Any pointers to specific script/style handles will be appreciated!

  • The only thing that I could to for you is to dig through the code myself and find all of them, figure out the handles and see what happens if I remove them. I’m just another user, not the developer, and would not have such a list, nor would anyone else that would read this.

    There are some settings that can be filtered that determine if ACF loads some specific scripts and these can be found here You could add filters that return false for these when on the front end of the site if they will not be used.

  • Ah, thanks John! I see this list includes some hogs like Select2…

    I have already created a support ticket to ACF devs, let’s see how that goes. If I get any results, I’ll report back!

  • @scooterlord – I appreciate that this may have changed since you asked these questions several years ago, but did you ever manage to find a definitive list of which stylesheet can be removed with which handle?

    – The ACF documentation is generally great and very detailed but wouldn’t having this documented on the website not be a relatively straightforward addition?

    Apologies if I just have found it yet – if it exist, any idea where it is?

    I’m trying to remove the _fields.scss style only, but whatever handle I try, it seemingly keeps removing the _global.scss as well.

  • Hello @svsdesign. I had to dig through the plugin files to find this, however, here are the ones I found/needed to remove:

    acf_update_setting('enqueue_select2', false);	
    acf_update_setting('enqueue_datepicker', false);
    acf_update_setting('enqueue_datetimepicker', false);
    acf_update_setting('enqueue_google_maps', false);
Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.