Sometime back I’ve written few articles on How to Speed up WordPress blog by .htaccess method and complete guide with list of all steps with description. This is my continuous effort to make some more optimization on WordPress site.
Today I was analyzing HTML output of my site Crunchify.com and suddenly noticed few non-required loaded Java Scripts. Few Java Scripts are common for all WordPress installation and some are for themes created by Genesis Framework. In this tutorial we will go over steps on how to get rid-off those unnecessary Java Scripts.
But let’s first take a look at – Why Site Speed is so Important?
You may have already heard but most of the visitors expect your site to load within a second or two. If your site’s page load time is greater than 3 then there are higher number of possibility they may never come to visit your site again. Not only that, but Google has now included site speed in ranking algorithm. In other words – your site’s speed effects SEO, so if your site is slow, you are losing visitors by having reduced rankings in search engines.
Faster page loading with better design should your goal as a web blogger/developer. You may want to visit complete guide.
Now let’s try to remove some unwanted JavaScripts.
Remove comment-reply.min.js completely
In the default WordPress template, the comment-reply.js
script is included on all single post pages, regardless of whether nested/threaded comments is enabled.
In which cases you may want to remove comment-reply.min.js?
- If you have disabled nested/threaded comments
- If you have disabled comments completely
- If you moved to Disqus comment platform
- If you moved to Livefyre comment system
Just put below code to your theme’s functions.php file and you will not see it loaded at front-end.
// Remove comment-reply.min.js from footer function crunchify_clean_header_hook(){ wp_deregister_script( 'comment-reply' ); } add_action('init','crunchify_clean_header_hook');
Remove jquery-migrate.min.js script
WordPress 3.6 onwards during WordPress initialization it loads JQuery default script and migration script. jQuery Migrate Script is used to load any deprecated APIs and functions that were removed in jQuery 1.9. In most cases you don’t need this.
If you want to check whether your site requires jquery-migrate.js
, open wp-config.php
and this line of code: define('SCRIPT_DEBUG', true);
. That way you can monitor any errors. Don’t forget to remove this when you put your site live!
Also, try to load jQuery
from Google Hosted CDN Library
. jQuery is being used on a lot of sites including the big ones. Google Library has become the standards for including scripts in web design. There are more number of chances that Google Hosted jQuery is already loaded on your visitors’s browser which may prevent loading jQuery from your site’s wp-includes/js
folder.
Put below code into your theme’s functions.php file and you will achieve both above points.
function crunchify_remove_jquery_migrate( $scripts ) { if ( ! is_admin() && isset( $scripts->registered['jquery'] ) ) { $script = $scripts->registered['jquery']; if ( $script->deps ) { $script->deps = array_diff( $script->deps, array( 'jquery-migrate' ) ); } } } add_action( 'wp_default_scripts', 'crunchify_remove_jquery_migrate' );
Before:
After:
Remove responsive-menu.js script
If you are using Genesis Framework then checkout your Child theme functions.php
file, you may see responsive-menu.js
and dashicons.css
. I’m using Elevent40 theme on Crunchify and for my need I don’t want to use those both on site. If you also don’t want to use responsive menu and dashicons then you try removing both lines from file.
I would recommend to follow below thumb of rules for any site:
- Try avoiding plugin as much as possible. Use only required plugins. Plugins add lots of unnecessary JS and CSS files on your site which most of the time not adding any value.
- Try putting only Google Ads on your site than other ad codes. Google Ads are optimized and served from their own caching domains.
- For social sharing plugin – I would suggest to use non-java based option for better site speed.