I am in perpetual pursuite of reducing page time. I think it not only helps your SEO ranking but also provides a better user experience. So it is a win-win. That said, when I ran a Speed Test on one of the page, I noticed it was loading some external 3rd party scripts that were slowing down the TTFB and First Paint time.
Upon further digging using webpagetest.org and gtmetrix.com, it was clear that Contact Form 7 (with Google Captcha enabled) was adding a few external scripts that were not needed. For example, I did not need the Contact Form 7 plugin loaded on the Cart and Checkout page.
What You Need
- Download Plugin Organizer
- A speed tool like gtmetrix.com or webpagetest.org
Without further ado, I will present below the steps I followed. But before we do that, let me first acknowledge that these are the steps provided to me by the author of the Plugin Organizer plugin. I do not take credit for these. The plugin author is very helpful and guided me through this process. I hope you will find it useful.
Step 1: Determine what scripts/styles need to be excluded
First, you have to determine what scripts/styles are slowing down your page. For this you can use gtmetrix.com or any other speed test site if your preference. Usually, I use both gtmetrix.com and webpagetest.org together because they complement each other quite well.
Here is an example of the summary. Pay attention to the numbers highlighted. The page size and number of requests is very important for determining whether your un-needed scripts/styles are loading.
Now, let us dig a bit deeper. The Waterfall view of gtmetrix.com is where I find the scripts that I need to unload. The screenshot shows below the JS and CSS resources loaded for the page, sorted by Size. I find the Sorting feature useful because I can attain significant optimization by removing the bigger scripts/styles first.
After the speed analysis, I determined that I did not want Contact Form 7 to be loaded on all the pages.
Step 2: Configuration of Plugin Organizer
Brace yourself, this is not as easy as it seems. Plugin Organizer is a very powerful tool. It allows incredibly fine control over how and which plugins can be enabled/disabled on a certain page/post.
- Install Plugin Organizer
- Activate Plugin Organizer
- Setup Plugin Organizer
Here is the screenshot for my settings for Plugin Organizer. Of note is the highlighted post types that I wanted to use Plugin Organizer for. Also, note the global settings. You can read up on each of these settings on the Plugin Organizer documentation site.
For me, the “Fuzzy URL Matching” and “Ignore URL Arguments” parameters need to be ON.
Disable the affected plugin globally. Here is the screenshot for my case – Contact Form 7 has been disabled Globally, i.e. it will not load at all on any pages/posts.
Step 3: Setup Plugin Filters
Here is the crux of it all. The logic, so to speak. In my case, I am enabling the CF 7 plugin on the 2 pages. Note the priority of filters.
Filter 1: CF 7
The 2 URL’s (permalinks) are the ones that this filter affects.
Filter 2: CF 7 JSON
In this case, there is only 1 URL that will be impacted. It is a specially formulated URL to select the URL that CF7 submits the form to. Notice the priority set to 4 in this case. The priority is important for this to work correctly, as it controls the execution order of the filters.
Step 4: Clear your cache(s)
After you have made the above changes, make sure to clear your cache(s) completely. Run the speed test again and verify that the un-needed scripts/styles are not being loaded anymore.
There you have it! With this configuration, I can successfully exclude a plugin from loading on a certain page/post. You may have to tinker with the priorities and Permalinks to get it working for your specific use case. Let me know in the comments if you think this is useful. For me, this was a great tool in easily reducing the page load time across the site in one shot. It is a clean way to exclude plugins from loading on every page.
Leave a Reply