Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

WordPress loading Jquery in footer

Featured Replies

Been messing about with a few wordpress boilerplates lately and now have Jquery loading in the footer via functions.php;

if( !is_admin()){
wp_deregister_script('jquery');
wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"), false, '1.3.2', true);
wp_enqueue_script('jquery');
}

 

Is it really worthwhile putting in a fallback call to a local copy of Jquery? If so, how? I originally had this in my header section;

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
 <script>window.jQuery || document.write('<script src="<?php echo get_template_directory_uri(); ?>/js/libs/jquery-1.7.1.min.js"><\/script>')</script>

 

It seems like a logical thing to have a fallback but just unsure how to implement this using the wp_enqueue and functions.php call.

Personally i wouldn't bother with a fallback.

I understand that putting all your faith in the external copy may be a wrench but at the end of the day these things just have to done and gotten on with.

  • Author

Personally i wouldn't bother with a fallback.

I understand that putting all your faith in the external copy may be a wrench but at the end of the day these things just have to done and gotten on with.

Now awaits google to go down lol :)

Hey man, I think you should always have a fallback to you local copy.

Last week the Google CDN was down for a few minutes :)

I remember seeing and article about this exact problem last Christmas. I'll dig through my bookmarks, see if I can find it.

 

EDIT: Found it, but I'm interested in seeing what Chris comes up with so I'll post the link to it after he's finished.

Edited by Spitfire

EDIT: Found it, but I'm interested in seeing what Chris comes up with so I'll post the link to it after he's finished.

 

Ha! No pressure, then...

Ha! No pressure, then...

 

Consider the pressure switch activated ;)

 

I was actually thinking about this question again the other night and i'm not happy with the original answer i gave (and i think i knew that). Fall back never hurts so why not do it?

 

I shall amend my ways from now on and have fall back to a local copy :)

Personally, I'd stick to either just the CDN or just a local copy. Having a fallback in your functions.php basically means making a HTTP request to check that the CDN is still there on every time you refresh or change pages.

If you don't think it's reliable enough to use the googleapis then I'd just have a local copy. Can't see point of both?

  • Author

Forgot about this! Am I right in thinking that my first example is the correct way of calling Jquery and that the second example (simply placing it in the header/footer) isn't really the way to go?

Personally, I'd stick to either just the CDN or just a local copy. Having a fallback in your functions.php basically means making a HTTP request to check that the CDN is still there on every time you refresh or change pages.

 

So i guess this would negate any reason to use a CDN version in the first place?

Hmmm... I suppose it would. I didn't really think it that far through.

 

Come to think of it, that'd only be an issue if the CDN version was off-line and I'm sure that wouldn't happen much.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.