Uncaught TypeError: a.indexOf is not a function – WordPress

Updated on June 15, 2021

I have been using Preloader WordPress plugin almost in all of my client websites. But the plugin ended up throwing “Uncaught TypeError: a.indexOf is not a function” error when W3TotalCache plugin was enabled.

The error occurred in preloader-script.js file which had the following code.

jQuery(window).load(function() {

jQuery('#wptime-plugin-preloader').delay(250).fadeOut("slow");

setTimeout(wptime_plugin_remove_preloader, 2000);
function wptime_plugin_remove_preloader() { 
jQuery('#wptime-plugin-preloader').remove();
}

});

What does the error Uncaught TypeError a.indexOf is not a function mean?

The error was due to the  jQuery event alias .load which was deprecated since jQuery version 1.8. The latest versions of JQuery require .on() method to be used instead of .load() method.

Well, I could finally fix the issue. Here are the solutions.

Solution 1: Check if jQuery migrate is disabled in W3TotalCache Plugin

By default WordPress loads jquery-migrate.js library to preserve the compatibility of jQuery codes developed for versions older than 1.9. W3TotalCache allows the user to disable the loading of JQuery migrate under General Settings > User Experience section. Enabling "Disable jquery-migrate on the front-end" checkbox will remove the jQuery migrate library from the front-end and thus removing the compatibility support for codes written for older versions of jQuery. So unchecking "Disable jquery-migrate on the front-end" will solve the issue.

Uncaught TypeError - jquery migrate

Solution 2: Replace .load() method with .on() method

You may disable the jQuery migrate library via W3TotalCache and still make the preloader-script.js to work by replacing the .load() method with .on() method. All you need to do is, open the preloader-script.js file and replace the code with the following.

jQuery(window).on('load', function(){

jQuery('#wptime-plugin-preloader').delay(250).fadeOut("slow");

setTimeout(wptime_plugin_remove_preloader, 2000);
function wptime_plugin_remove_preloader() {
jQuery('#wptime-plugin-preloader').remove();
}

});

Note: The information provided in this page is based on WordPress version 5.7.2, the preloader plugin version 1.0.9 and W3TotalCache plugin version 2.1.3.

Was this article helpful?

Related Articles

Leave a Comment