Hello,
We are using Forms to display some basic contact forms, only basic input and textarea.
Unfortunately this also loads some Javascript, i.e. CodeMirror and Select2 into the frontend.
CodeMirror more than all of our other scripts together and bloats our loading times (even with caching and js optimization).
Select2 is quite a large lib, we don't use too.
Together the seem to be about 2/3 of all of our JavaScripts.
So my suggestions:
Only load these scripts needs if needed or allow them to be disabled.
Thanks,
Adrian
Hi Adrian,
Thank you for contacting us and I'd be happy to assist.
We have an internal ticket to introduce more efficient loading of scripts and styles in future releases, but I'm afraid, I don't have a time estimate to share the moment.
For now, a workaround can be to use some custom code to dequeue and deregister the unnecessary scripts.
Example:
add_action( 'wp_enqueue_scripts', 'remove_default_scripts', 20 );
function remove_default_scripts() {
wp_dequeue_script( 'toolset_select2' );
wp_deregister_script( 'toolset_select2' );
wp_dequeue_script( 'toolset-codemirror-script' );
wp_deregister_script( 'toolset-codemirror-script' );
}
The above function will remove the "select2" and "codemirror" scripts 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.
regards,
Waqar
Hello Waqar,
Thank you, this is okay for me now.
Looking forward to an integrated solution in a future release.
Thanks,
Adrian