Skip Navigation

[Resolved] Dequeue unnecessary Toolset javascripts

This support ticket is created 3 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+00:00)

This topic contains 8 replies, has 2 voices.

Last updated by Jamal 3 years, 9 months ago.

Assisted by: Jamal.

Author
Posts
#1652303

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!

#1652667

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

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.

#1654423
Capture.PNG

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!

#1656055

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

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!

#1657239

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

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.

#1657289

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!

#1657353

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

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.

#1657507

My issue is resolved now. Thank you!

#1698529

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

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!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.