Hi,
I'm wondering if these files need to load sitewide or if I can just have them load on pages where I actually have toolset forms.
/wp-content/plugins/cred-frontend-editor/vendor/toolset/common-es/public/toolset-common-es-frontend.js?ver=140000
/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/res/lib/bootstrap4/js/bootstrap.bundle.min.js?ver=4.5.3
/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/res/lib/select2/select2.css?ver=5.7
/wp-content/plugins/cred-frontend-editor/vendor/toolset/common-es/public/toolset-common-es-frontend.js?ver=140000
wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/toolset-forms/js/main.js?ver=0.1.2
/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/toolset-forms/js/date.js?ver=0.1.2
If they don't need to load sitewide, is there a simple way to stop this?
Thanks,
Tim
Hi Tim,
Thank you for contacting us and I'd be happy to assist.
There is no built-in feature available for this at the moment. There is a plan to make the loading of CSS and JS code from Toolset more efficient in future releases so that they're only included on the pages, where they are absolutely required.
For now, I'll not recommend stopping these files from loading using some custom code or any other workaround, as it can result in unexpected results or missing features.
regards,
Waqar
Thanks. But if there are pages with no Toolset forms, then stopiing these files from loading shouldn't have any effect, would it?
Tim
So, I'm still not sure why I need to load files for forms on pages I'm not loading forms? Why would removing these, via some code in the functions/php file, have potential "unexpected results or missing features."
Also if I'm not using Toolset Blocks why would this load?
I should be able to remove this withouth any unexpected results right?
/wp-content/plugins/wp-views/vendor/toolset/blocks/public/css/style.css?ver=1.4.1
This all just seems crazy that I have to load 6 extra files on pages where they are not necessary. It's a big page load slow-down.
Tim
Thanks for writing back.
The files that you referenced in your first message are not just needed for Toolset Forms and some of them are needed for other items like a grid, search filters, gallery, etc.
The toolset plugins provide the ability to place its elements like views, maps, and forms on any page or post. The automatic detection for whether these elements are available on a particular page or not can be challenging and if not carefully implemented, it can result in reduced performance, instead of improving it.
For now, if you'd prefer to remove particular scripts from loading you can use the "wp_dequeue_script" function:
https://developer.wordpress.org/reference/functions/wp_dequeue_script/
For example:
add_action( 'wp_enqueue_scripts', 'remove_default_scripts', 20 );
function remove_default_scripts() {
wp_dequeue_script( 'toolset-common-es-frontend' );
wp_deregister_script( 'toolset-common-es-frontend' );
wp_dequeue_script( 'toolset_bootstrap_4' );
wp_deregister_script( 'toolset_bootstrap_4' );
}
The above function will remove the script files with handles "toolset-common-es-frontend" and "toolset_bootstrap_4", from all front-end pages. To make this code remove these scripts only from the specific page(s), you can introduce conditions through WordPress conditional tags:
https://codex.wordpress.org/Conditional_Tags
Tip: You can use the "toolset_add_registered_script" filter in a temporary function to view the handles of all the scripts that are loading:
add_filter( 'toolset_add_registered_script', 'custom_filter_to_view_scripts' );
function custom_filter_to_view_scripts( $scripts ) {
print_r($scripts);
return $scripts;
}
I hope this helps and please let me know if you need any further assistance around this.