Tweet about this on TwitterShare on FacebookShare on Google+Share on LinkedIn

WordPress Super OptimizationNobody likes slow loading websites and pages right? Even though the average internet speed has risen considerably there are still plenty of them out there. If the size of your page is extremely large in size, or there are scripts that use a lot of resources it won’t matter how much download speed you have. It will still load slow.

Optimizing, if done right can definitely help. However, it can also be extremely time-consuming, and in some cases a complete waste of time. It’s not worth spending hours on something that is only going to gain you a few milliseconds. That’s not really what you are after.

There are numerous topics and tips out there about how to speed up your site’s load time. We usually look for the more obvious, and usually the easier ones that can be accomplished in a reasonable amount of time. But, at some point you have to say enough too. You can’t spend all your time worrying about speed and performance. You do have a website or business to run right?

With that in mind there are less popular and talked about things you can do. For example, just about every WordPress plugin you install will include a css file, js file, or both and in some cases more than one of each. Css files are usually loaded in the header near the top of your page. Js files vary. Some in the header, some in the footer, and sometimes in between depending on the plugin and what it does. The important thing to keep in mind is that they get loaded everywhere whether they are needed on the particular post, page, archive, category, tag, archive, etc., or not.

For example, say you install a contact form plugin. Most likely you will only create one contact page. That page would be the only one that needs the associated plugin css and js files to be loaded, but like I said WordPress will load them everywhere on your website.

So what you can do if you really want to optimize is instruct WordPress to load the contact form css and js files only on your actual contact page. This will reduce the page size, and the number of requests as well.

If you have other plugins that are loading specific css and js that are only needed for a certain page you could do the same thing. Only load them where they are actually needed.

So how do you go about that?

You dequeue them everywhere except where they are needed. You need to find the css and js handles (names) the plugin is using to do this.

It’s fairly easy to find the css handle by simply viewing the page source and looking for id:

Contact Form 7 css Handle

The id is the css handle. You just remove the “-css” part of the id. So, in this case the css handle is “contact-form-7“. In other words, “contact-form-7-css” becomes “contact-form-7”.

The js handle involves searching through the plugin .php files to find the handle name so you can dequeue it (or them).

Once you find them there are several methods of dequeue them, but what you are basically going to tell WordPress is that if it’s not your contact page, then dequeue them. Otherwise, do nothing (or enqueue as usual).

This may sound a little confusing, but it’s pretty simple once you understand the process.

I’ll use the popular WordPress Contact Form 7 as an example.

I add the following code to my theme functions.php file:

The handles were found in the: /wp-content/plugins/contact-form-7/includes/controller.php file.

What this code is saying is if is not the contact-me page or not page number 85, then dequeue the style, and the two js script files. The contact-me is the WordPress slug for that page, and it is number 85, which can be found in your WordPress dashboard pages section. See the screen shot below.

Find the page slug by clicking on your contact page “quick edit” link. In this case, the slug is contact-me.

Contact Me Slug

Find the page number by hovering your mouse over your contact page link and finding the number within the link. In this case, 85.

Contact Me Page Number

You would need to change the code above to reflect your contact page slug and page number.

After that save the changes to your theme functions.php file.

If you have a cache plugin, minify plugin, and/or external 3rd party caching mechanism such as Cloudflare you will want to clear out the cache(s) for the changes to take effect. Otherwise, you will have to wait until it expires, which will vary in the amount of time it takes depending on your settings.

This is more along the lines of an intermediate to advance optimization technique. I don’t recommend it to those of you that are not comfortable with it. The only file you are actually modifying is your theme functions.php file. So, worst-case scenario you simply remove the code if you do something wrong.

You can also wp_deregister_style/script & wp_dequeue_style/script like:

Usually just dequeue is enough, but you can get more technical and do both.

As I said this is just one example. It’s certainly possible that other plugins are adding css files, js files, or both where they are not needed as well, and you could apply the same or similar process.

If so just be sure to use a different function name for each. That would be this part:

You would want to change:

To a unique name like:

And the same with:

You would change it to:

The 100 part is the priority. You can either remove it completely like:

Or increase/decrease the priority like:

Finding the js handles can sometimes be a challenge if a particular plugin has a significant number of files and folders. Some are really easy to find, and others are more difficult.

If you can find the handles fast and easy enough it could be worth your time if you are into optimization. Otherwise, if it’s only going to save you a few kilobytes and takes a long time to find the handles, then it may not be worth your time.

If nothing else it’s something to think about and to consider at a later time at the very least.

About: Jeremy LeSarge - AKA: Ray (212 Posts)

I am the site owner and administrator of I provide help and tips for Boonex Dolphin on the main part of this website where you will also find an assortment of other resources. Here, on the blog I write about a variety of topics surrounding WordPress, technology, social media/networking, SEO, and webmaster resources.