Home Blogging Blogging Tips How to speed up your WordPress blog by excluding certain JavaScript and...

How to speed up your WordPress blog by excluding certain JavaScript and CSS files


If you own a WordPress blog, you should know by now that the more plugins you’ve got, the slower your blog/website gets. This is because each installed and activated plugin usually has their own JS (JavaScript) and CSS (Cascading Style Sheets) running on every page and post.

Obviously, you don’t need them to be running on every part of your site.

For example, you don’t need a Contact form plugin to load their resources when a visitor is browsing your articles. Or in my case, I don’t need my reviews-related plugins to load their JS and CSS files if my reader is not browsing a review article.

By tweaking the functions.php that comes with your installed theme (or with the Child theme), you can add codes to check and deregister these unnecessary scripts and styles. Ideally, you should be using a child theme so any modifications you make to the functions.php is not lost when the theme gets an update.

Here is a snippet from my functions.php:


In order to be able to deregister the JS and CSS files, you need to know the name of the handles on each of the plugin which files you want to deregister. I use a plugin called “WP Asset CleanUp” to find out about the handles on a post type and then add them to my_deregister function.

JS CSS handle

WP Asset Cleanup does a similar thing to what we are doing, but it’s quite limited in my opinion. It cannot do post categories or tags and therefore, we’d need to do these manually using the functions.php.

On my example above, I unload many scripts and files that are only necessary if my readers are on my Gadget Reviews posts. You can further tweak the script to suit your needs. For example, you probably want to deregister commenting-related scripts and styles at your home page, and so on (using is_page, is_home, etc).

After the tweaks, I’ve managed to gain a 15% speed improvement which is not bad at all.

There are also others that you might want to disable such as Emoji support on WordPress (if you don’t use Emojis on your blog) or comment-related files if you disable comments on your blog.

Related Posts at Craving Tech

How to reduce inode usage (files and folders) with a web hosting limit If you are hosting your blog or website on a shared server (or I guess, any server), you may be hitting your inodes limit at some point. In a nuts...
How to enable SSH on VaultPress (at HostGator or other web hosting) How to enable SSH on VaultPress - If you are blogging on WordPress, there is a higher chance of you backing up your WordPress blog through VaultPr...
Custom Web Design vs Templates Note: This is a guest post written by Blake Davies After a while, your company’s website becomes obsolete and needs not only improvement but a ...
Why WordPress is a Perfect Solution for Your Business’ Blog Note: This is a guest post written by Blake Davies Originally launched in 2003 as a blogging platform, WordPress is probably the most widely-us...
50 Best Technology WordPress Themes Note: This is a guest post written by Sunalini Rana 50 Best Technology WordPress Themes - Technology websites represent the epitome of technology b...