Skip Navigation

[Resolved] Dequeue unused styles and scripts

This support ticket is created 3 years, 11 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.

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: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 3 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#1857239

Tell us what you are trying to do?
I'm only using 3 views on my home page and nowhere else on the site. However, all the Toolset CSS files and scripts load on every page. So, I'd like to only enqueue Toolset files only on the home page.

Is there any documentation that you are following?
No, but I did check support articles.

What is the link to your site?
hidden link

#1857421

Hello,

Yes, you are correct, since Toolset Views plugin is using shortcode to render views, and it doesn't know if the page/post contains a view shortcode when rendering HTML header area, so Toolset Views plugin enqueue some CSS/JS files in all front-end pages/posts.

And we do have a plan to optimize all of the assets(CSS/JS files) loaded by Toolset, this project will be completed maybe one or two months, that means if I provide some custom codes to dequeue those files, the custom codes may not work in the future version of Toolset plugins, so you might consider to wait for the new version of Toolset plugins(with optimize assets loaded by Toolset feature) are released.

#1859149

Hi Luo,
Thanks for the reply and I'm glad to hear it's on your roadmap. I'd like your custom code to dequeue the files please. I'll add it to my code snippets so I can quickly disable when your update is ready over the next few months. Thanks.

#1861139

Please try to those codes:

add_action( 'wp_enqueue_scripts', 'ts_dequeue_scripts', 1, 999 );
add_action( 'wp_print_scripts', 'ts_dequeue_scripts', 1, 99 );
add_action( 'wp_print_footer_scripts', 'ts_dequeue_scripts', 1, 99 );
function ts_dequeue_scripts(){
	if(is_page(123)){ // replace 123 with the front-page ID
		return;
	}
    wp_dequeue_script( 'wptoolset-field-date' );
    wp_dequeue_script( 'views-blocks-frontend' );
    wp_dequeue_script( 'toolset-common-es-masonry' );
    wp_dequeue_style( 'toolset-common-es' );
    wp_deregister_style( 'toolset-common-es' );
    wp_dequeue_style( 'toolset_blocks-style-css' );
    wp_deregister_style( 'toolset_blocks-style-css' );
    wp_dequeue_style( 'views-pagination-style' );
    wp_deregister_style( 'views-pagination-style' );
    wp_dequeue_style( 'toolset-select2-css' );
    wp_deregister_style( 'toolset-select2-css' );
}

You will need to replace 123 with your home page ID.