advancedforms / advanced-forms

WordPress plugin to create forms using Advanced Custom Fields
75 stars 14 forks source link

Disable ACF style and scripts enqueuing #69

Closed ghost closed 4 years ago

ghost commented 4 years ago

when activating this plugin, bunch of codes are inserted:

/acf/assets/js/acf-input.min.js
/acf/pro/assets/js/acf-pro-input.min.js
/acf/assets/inc/select2/4/select2.full.min.js
/acf/assets/inc/timepicker/jquery-ui-timepicker-addon.min.js
...

/acf/assets/css/acf-global.css
acf/assets/css/acf-input.css
....

and many other styles. is it possible to disable theses o they are not loaded on the website?

ghost commented 4 years ago

it can be removed here:
https://github.com/advancedforms/advanced-forms/blob/c705c4572adcd812f21eba8aeb65ae08071ca529/core/forms/forms-rendering.php#L76-L82

but the form will not work properly any more, can you change this in the upcoming release so it doesn't load all these files?

ghost commented 4 years ago

@fabianlindfors can you please create an option in the settings that will remove

     acf_enqueue_scripts(); 
     wp_enqueue_script( 'af-forms-script', AF()->url . 'assets/dist/js/forms.js', array( 'jquery', 'acf-input' ), AF()->version, true ); 

from forms-rendering.php file? maybe a simple checkbox that says don't load any files. Or it could be done via the shortcode where we can set it to false so these are not loaded, any thoughts?

fabianlindfors commented 4 years ago

Hi! Sorry about the late reply.

I would recommend using wp_dequeue_script() (https://developer.wordpress.org/reference/functions/wp_dequeue_script/) to remove the scripts and styles that you deem unnecessary.

I want to cut down on the number of styles and scripts enqueued by ACF but it has proven quite hard. Hopefully they will be reduced in a future version.

ghost commented 4 years ago

there are too many files to dequeue, can you create an action which we can set to false in order to disable styles and scripts?

dsplz commented 2 years ago

There should be an option for this – pretty annoying

fabianlindfors commented 2 years ago

Hey, @dsplz!

I've added a guide to the documentation with an example of how to do this: https://advancedforms.github.io/guides/decreasing-number-of-scripts-and-styles/. The hard part is knowing what ACF adds but I've tried to find all the different scripts and styles and compiled them there.

abombelli commented 7 months ago

The problem is, all the styles and scripts are loaded also on pages without any forms. The amount of load code is enormous. If at least we could limit it to only pages with forms.