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 https://developer.wordpress.org/reference/functions/wp_dequeue_script/ and https://developer.wordpress.org/reference/functions/wp_dequeue_style/. 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 https://www.advancedcustomfields.com/resources/acf-settings/. You could add filters that return false for these when on the front end of the site if they will not be used.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.