Remove jQuery Script from header

Posted in: Newsmag
Post count: 142

Hi,

I wanted to know if this feature can cause errors to your thema:

Let me know, thank you

// Remove jQuery Migrate Script from header and Load jQuery from Google API
Function reassign_jQuery () {
Wp_deregister_script (‘jquery’);
Wp_deregister_script (‘jquery-core’); // do not forget this
Wp_deregister_script (‘jquery-migrate’); // do not forget this

Wp_register_script (‘jquery’, ‘https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js’, array (), ‘1.12.4’, TRUE);
wp_enqueue_script (‘jquery’);
}
If (! Is_admin ())
Add_action (‘init’, ‘reassign_jQuery’);

Post count: 142

Or better this second version ??

// Remove jQuery Migrate Script from header and Load jQuery from Google API
function simmonsbunny_remove_jquery_migrate_load_google_hosted_jquery() {
if (!is_admin()) {
wp_deregister_script(‘jquery’);
wp_register_script(‘jquery’, ‘https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js’, false, null);
wp_enqueue_script(‘jquery’);
}
}
add_action(‘init’, ‘simmonsbunny_remove_jquery_migrate_load_google_hosted_jquery’);

Post count: 9544

Second version, mine, is used on dozen of my sites right now ?

Post count: 142

Hi Chris,

I also wanted to have confirmation from thema developers that can work all fine.

If they have time to respond, they can help.

Post count: 9544

Well, simple way to test … try it; if your site works, then it works.

It works fine on all my TagDiv sites running NewsMag, so not sure why it would not work for you. All it does is load the jquery script from Google CDN — same way Google fonts loaded — vs loading the local copy from your theme folder/WP install.

However, you *do* want to check to see if perhaps you need to update that to a later version, easily checked by seeing which version is being loaded now with WP/theme. e.g., 1.12.4 might need to be 2x or 3x (1.12.14 was last of v1). 1.12.4 was the standard as of WP 4.6.

No other voodoo involved 🙂

If you don’t have a specific reason to do this, then probably shouldn’t.

REF:
https://developers.google.com/speed/libraries/

  • This reply was modified 9 years by simchris.
Post count: 23312

Hello orlando,

Confirm Chris’s solution. Many times, when other clients give a solution and it is good, we do not intervene anymore. We intervene when the solution is not right. You should try the hint’s from Chirs tutorial like this -> https://forum.tagdiv.com/topic/tutorial-chriss-custom-optimizations-for-functions-php-etc/page/2/

Thanks for your understanding!

Post count: 9544

Generally the reasoning behind doing this is on a slower hosting account, or for “sometimes” better mobile use. As in all things you need to TEST doing it both ways to see which provides better page load time.

For example, with https and http/2 on a modern 2017/18 next gen setup, running PHP 5.6 or PHP 7 with opcache on, might be better to load locally vs externally.

A lot of stuff I posted was primarily to “get stuff out of the header…” for better score couple of years back.

Viewing 7 posts - 1 through 7 (of 7 total)
The forum ‘Newsmag’ is closed to new topics and replies.