Hi,
I understand that I can dequeue unnecessary javascript from toolset which will help to improve page load time.
Do I use the add_action() hook 'wp_print_scripts' & 'wp_print_styles'?
Also, how can I tell which javascript is for what and what is the dequeue scripts?
I want to dequeue the javascript file 'toolset-common-es-masonry.js' from '/wp-views/vendor/toolset/common-es/public/toolset-common-es-masonry.js', what is the name of that script file?
Thank you!
Hello and thank you for contacting the Toolset support.
You can use the add_action() hook 'wp_print_scripts or another hook that came before WordPress generates the page scripts and styles. Check these previous threads for different examples:
- https://toolset.com/forums/topic/dequeue-unwanted-scripts-and-embedded-snippets/#post-516457
- https://toolset.com/forums/topic/how-to-dequeue-unused-scripts/#post-120647
The handler for the masonry script is called "toolset-common-es-masonry", the following code should work, let me know if it does not and I will test it:
function cleanup_scripts() {
if ( !is_admin() ) {
wp_dequeue_script( 'toolset-common-es-masonry' );
}
}
add_action( 'wp_print_scripts', 'cleanup_scripts', 100 );
I hope this helps. Let me know if you have any questions.
Hi Jamal,
Thanks for providing the code to remove the masonry script, however, it's not working.
I have added that piece of code to my functions.php file and checked the view source, the masonry script is still there (screenshot attached).
Can you test the code out?
Thanks!
Hello and my apologies for the late reply, I do not work on Mondays.
I tested in a new installation with that code snippet and other variations in order to dequeue the masonry script to no avail.
Let me approach our 2nd Tier for assistance on this and I'll get back to you as soon as possible.
Thank you!
Hello! I got feedback from our 2nd Tier. The following code is working for pages that do not contain any Toolset views. Pages that do contain a view still get the masonry script loaded.
add_action( 'wp_print_scripts', 'ts_dequeue_scripts', 9999 );
function ts_dequeue_scripts( $handles ){
wp_dequeue_script( 'views-blocks-frontend' );
wp_dequeue_script( 'toolset-common-es-masonry' );
}
At the same time, we have escalated this to our developers and it will be fixed in a coming release, I can't tell exactly when. But, if you would like, I can escalate this ticket and get back to you when it is resolved. Otherwise, you can mark this ticket as resolved and keep an eye on our blog and changelogs.
Thanks Jamal!
It's working, but when I tried to dequeue only the 'toolset-common-es-masonry' it doesn't work.
(1) So does it mean I have to dequeue 'views-blocks-frontend' in order to remove 'toolset-common-es-masonry'?
(2) What does the 'views-blocks-frontend' script do?
(3) If the 'views-blocks-frontend' script is removed, will Toolset Filter views or basic views still work?
Thanks!
It won't work if you try to dequeue only "toolset-common-es-masonry", because it is a dependency for "tb-frontend-js" used in views, and "views-blocks-frontend" used in blocks. You will have to dequeue the dependency to make sure the script is dequeued, otherwise, the script is never queued alone, it il always queued as a dependency.
(1) Yes, if you are using blocks on your website. But, I expect that it won't work for pages that have a blocks view. At least until we fixed it.
(2) It is used in block-based views.
(3) If a block-based view is used, you won't be able to dequeue the script, at least until we get it handled.
My issue is resolved now. Thank you!
Hello,
Our 2nd Tier has come up with a solution for this. Add the following code to your site:
add_action( 'wp_print_scripts', 'ts_dequeue_scripts', 1 );
add_action( 'wp_print_footer_scripts', 'ts_dequeue_scripts', 1 );
function ts_dequeue_scripts(){
wp_dequeue_script( 'views-blocks-frontend' );
wp_dequeue_script( 'toolset-common-es-masonry' );
}
All the best!