How to One-Click Disable Scripts in WordPress with perfmatters

disable scripts in WordPress

When it comes to WordPress there are a lot of plugins out there that aren’t coded for performance. They are coded for usability. While usability is tremendously important, performance seems to always get left out of the equation, which is one reason WordPress has such a bad wrap in the non-WordPress developer community. Today I want to show you how to easily one-click disable scripts in WordPress with our new perfmatters plugin.

Disable Scripts in WordPress on a Per Post/Page Basis

As some of you know, my brother and I just recently launched our perfmatters plugin, which is a lightweight WordPress performance plugin. Besides having optimizations you can easily enable, it also now has what we are calling a “Scripts Manager”. This allows you to easily one-click disable scripts in WordPress on a per post/page basis. Or even disable things by custom post types!

Scripts Manager
Scripts Manager

This is very powerful and can drastically increase the speed on your WordPress sites (especially your homepage). A few examples of what this can be used for:

  • The popular Contact Form 7 plugin loads itself on every page and post. You can easily disable it everywhere with one click and enable only on your contact page.
  • Social media sharing plugins should only be loaded on your posts. You can easily disable it everywhere and load only on post types, or even custom post types. For example, the social sharing plugin you see right now on the sidebar of this post, doesn’t load on any of our pages, thanks to the perfmatters plugin.

And you might be wondering, does perfmatters work with caching plugins like WP Rocket and Cache Enabler? Yes. It also works great on hosts like Kinsta and WP Engine who have server-level caching. The perfmatters plugin is not a replacement for your caching solution, it’s meant to work with them to further increase your speeds.

Why Are Plugins Coded This Way?

You might be wondering why all plugin developers don’t just load their scripts only when the plugin is detected on the page? Well, actually, it is a little more complicated than that. For example, if you have a plugin like Contact Form 7, it also has shortcodes which allow you to place it anywhere. This includes dropping it in a widget. With WordPress, it is much harder to query data from them when you dequeue scripts as opposed to querying data from post or page meta data.

Therefore, a lot of times this is due to usability issues. The less chance they have for a plugin to break, the fewer tickets and support they will have. However, with a lot of plugins on the marketplace, there are ways to get around this and code for performance if they really wanted to.

Speed Tests With Perfmatters Plugin

So we decided to run a few tests for you to see the performance differences when you disable scripts in WordPress.  Also note, all of our sites are pretty optimized already. If you were to run this on an unoptimized site you definitely will see even more speed improvements.

A lot of people ask us why we don’t offer web performance audits, and the answer is, we don’t have time. But we do highly recommend Mike over at Codeable if you need a performance audit on your WordPress site. We chat all the time and agree on pretty much everything performance wise. You are in good hands with him.

Without perfmatters on nogluten.io

We are using our nogluten.io site since it is bigger. We first temporary disabled Google AdSense on the site so we could run tests. Why? Because when AdSense is enabled it loads different amounts of ads each page load, which makes it impossible to run comparison tests like this. We then ran five tests on Pingdom and took the average. This is with perfmatters disabled.

Speed test without perfmatters
Speed test without perfmatters

With perfmatters on nogluten.io

We then enabled the perfmatters plugin and ran five more tests on Pingdom, again taking the average. As you can see, it decreased our total load times by 20.2%. And on our homepage alone we were able to reduce the number of HTTP requests from 46 down to 30! The page size also shrunk from 506.3 KB to 451.6 KB.

Speed test with perfmatters
Speed test with perfmatters

You can’t really argue with those results. And this is on top of our server-level caching.

Disabling JavaScript From Loading

Now you might be curious what all we disabled in the Scripts Manager, so we will show you. Of course, this will be different on every site. Here is a screenshot of JavaScript we disabled.

Disable JavaScript on homepage
Disable JavaScript on homepage

Here is the JavaScript disabled from loading on the homepage:

  • /wp-content/plugins/wp-shortcode/js/jquery.tipsy.js
  • /wp-content/plugins/wp-shortcode/js/wp-shortcode.js
    • Both the above scripts are being used by a shortcode plugin. With this particular theme, shortcodes aren’t used on the homepage.
  • /wp-content/plugins/extended-widget-options/assets/js/jquery.widgetopts.min.js
    • Used by the extended widget plugin we have running. This isn’t used on the homepage.
  • /wp-content/plugins/table-of-contents-plus/front.min.js
    • Used by a table of contents plugin, also not used on the homepage.
  • /wp-content/plugins/aawp/public/assets/js/scripts.min.js
    • Used by an Amazon affiliate plugin which isn’t used on the homepage.

Here is the JavaScript disabled from loading everywhere on the site except for on certain custom post types:

  • /wp-content/plugins/social-warfare/js/script.min.js
    • Used by our social media sharing plugin. This only needs to load on posts you want people to share.

Disabling CSS From Loading

Here is a screenshot of the CSS we disabled.

Disable CSS on homepage
Disable CSS on homepage

Here is the CSS disabled from loading on the homepage:

  • /wp-content/plugins/extended-widget-options/assets/css/widget-options.css
    • Used by widget plugin, not needed on homepage.
  • /wp-content/plugins/nogluten_old/css/style.css
    • Used by a custom plugin we wrote for the site, not needed on homepage.
  • /wp-content/plugins/table-of-contents-plus/screen.min.css
    • Table of contents CSS is not used on homepage.
  • /wp-content/plugins/aawp/public/assets/css/styles.min.css
    • Used by Amazon Affiliate plugin, not needed on homepage.
  • /wp-content/plugins/wp-shortcode/css/tipsy.css
  • /wp-content/plugins/wp-shortcode/css/wp-shortcode.css
    • Both of the above scripts are used by a shortcode plugin, not needed on homepage.

Here is the CSS disabled from loading everywhere on the site except for on  certain custom post types:

  • /wp-content/plugins/social-warfare/css/style.min.css
    • Used by our social media sharing plugin. This only needs to load on posts you want people to share.

What to Disable?

With many JavaScript and CSS files you should be able to tell what they are used by simply by looking at the name. For example “social_warfare_script” is obviously being used by the Social Warfare Plugin. If you aren’t sure about a particular file, you can always Google it. Or this is also again where hiring a web performance expert like Mike can come in handy. We are also going to be adding recommendations to the plugin and our documentation as time goes on.

Kevin Muldoon also published a great review and video explaining more of how the perfmatters plugin works if you are still confused.

As you can see, the perfmatters plugin can be a great solution to help further speed up your site. The ability to disable scripts in WordPress has never been easier! You don’t have to tweak anything you currently have running. It will work with your caching plugins. For a limited time, use our coupon code WOORKUP for 15% off.

Visit perfmatters

We are using the perfmatters plugin on all of our sites and hope you enjoy it as much as we do! We have a lot of great new features already planned for it and hope to make it the #1 lightweight performance plugin for WordPress. And don’t forget to read about the other performance features in perfmatters.

If you have any questions, always feel free to ask. We happy to answer.

GET MORE STUFF LIKE THIS

Marketing, WordPress, Blogging Tips, SEO and Reviews, once a week.

Thank you for subscribing.

Something went wrong.

Brian Jackson

Inbound marketer obsessed with SEO, WordPress, SaaS, and webperf. Want to see your product or service on woorkup? Hire Me

Leave a Comment

45 Shares
Tweet
Share
Share
Buffer