Paulund
2014-01-23 #wordpress

Stop WordPress Including jQuery Migrate File.

In WordPress version 3.6 when WordPress loads the built in jQuery file it will also load in the jQuery migrate file. The jQuery migrate file was introduced in version 1.9 of jQuery, it is used to load any deprecated APIs and functions that were removed in jQuery 1.9. There were a few deprecated functions in jQuery that were hard to use and inconsistent. In 1.9 the jQuery development team removed these functions to be replaced by easier to use functions such as the on() and off() functions. If you are using the latest version of jQuery on an older application and are using functions like live() then you will get errors because this function doesn't exist anymore. Including the jQuery migrate file with jQuery will fix this error by adding the live() function again.

Including jQuery In WordPress

jQuery is a built in script that comes with WordPress therefore it makes it very easy to load in your website, all you have to do is use the wp_enqueue_script() function passing in jquery as the handler.

add_action( 'wp_enqueue_script', 'load_jquery' );
function load_jquery() {
    wp_enqueue_script( 'jquery' );
}

As off WordPress 3.6 this would also include the jQuery Migrate script. Adding an extra file will obviously affect your page loading speed. This is only one extra file, which isn't a very big file but if your website doesn't use any deprecated functions then there is no need to load the migrate file. You can use the following code to remove the jQuery migrate on the front-end of your website, just add the following code to your functions.php file. This will take the WordPress default scripts, remove jQuery from it and therefore removing jQuery migrate, then we add jQuery back into the scripts which will just add the core files.


add_filter( 'wp_default_scripts', 'remove_jquery_migrate' );

function remove_jquery_migrate( &$scripts)
{
    if(!is_admin())
    {
        $scripts->remove( 'jquery');
        $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.10.2' );
    }
}

UpChecker

Reliable uptime monitoring and instant alerts for any website downtime.

  • Uptime Monitoring
  • Performance Monitoring
  • SSL Certificate Alerts
  • Domain Monitoring
  • DNS Checker
  • XML Sitemap Monitoring