Web Design Forum: WordPress loading Jquery in footer - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

WordPress loading Jquery in footer

#1 User is online   roothost 

  • Currently accepting new clients
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,463
  • Joined: 06-February 11
  • Reputation: 73
  • Gender:Male
  • Location:Lewes, East Sussex
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 January 2012 - 10:06 AM

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.
0

#2 User is online   MikeChipshop 

  • Small but imperfectly formed
  • Group: Moderators
  • Posts: 7,046
  • Joined: 19-April 10
  • Reputation: 503
  • Gender:Male
  • Location:Scotland

Posted 16 January 2012 - 12:46 PM

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.
0

#3 User is online   roothost 

  • Currently accepting new clients
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,463
  • Joined: 06-February 11
  • Reputation: 73
  • Gender:Male
  • Location:Lewes, East Sussex
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 January 2012 - 01:28 PM

View PostMikeChipshop, on 16 January 2012 - 12:46 PM, said:

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 :)
0

#4 User is offline   Pedro 

  • Expert
  • PipPipPipPip
  • View gallery
  • Group: Members
  • Posts: 740
  • Joined: 30-November 08
  • Reputation: 62
  • Gender:Male
  • Location:London
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 19 January 2012 - 10:28 AM

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 :)
0

#5 User is online   Renaissance-Design 

  • Available for custom WordPress work
  • View blog
  • Group: Moderators
  • Posts: 3,594
  • Joined: 12-August 10
  • Reputation: 559
  • Gender:Male
  • Location:South Wales
  • Experience:Web Guru
  • Area of Expertise:Designer/Coder

Posted 19 January 2012 - 11:56 AM

Have no fear, I'm working on this one today. Will let you know when I've got something, shouldn't be long.
0

#6 User is online   Spitfire 

  • Mighty Pirate™
  • PipPipPipPip
  • Group: Members
  • Posts: 891
  • Joined: 05-February 11
  • Reputation: 189
  • Gender:Male
  • Location:Berkshire
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 19 January 2012 - 12:27 PM

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.

This post has been edited by Spitfire: 19 January 2012 - 12:32 PM

0

#7 User is online   Renaissance-Design 

  • Available for custom WordPress work
  • View blog
  • Group: Moderators
  • Posts: 3,594
  • Joined: 12-August 10
  • Reputation: 559
  • Gender:Male
  • Location:South Wales
  • Experience:Web Guru
  • Area of Expertise:Designer/Coder

Posted 19 January 2012 - 12:47 PM

View PostSpitfire, on 19 January 2012 - 12:27 PM, said:

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...
0

#8 User is online   MikeChipshop 

  • Small but imperfectly formed
  • Group: Moderators
  • Posts: 7,046
  • Joined: 19-April 10
  • Reputation: 503
  • Gender:Male
  • Location:Scotland

Posted 19 January 2012 - 01:14 PM

View PostRenaissance-Design, on 19 January 2012 - 12:47 PM, said:

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 :)
0

#9 User is online   Spitfire 

  • Mighty Pirate™
  • PipPipPipPip
  • Group: Members
  • Posts: 891
  • Joined: 05-February 11
  • Reputation: 189
  • Gender:Male
  • Location:Berkshire
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 19 January 2012 - 01:19 PM

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.
0

#10 User is offline   oakleaves 

  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,395
  • Joined: 16-July 11
  • Reputation: 173
  • Gender:Not Telling
  • Experience:Nothing
  • Area of Expertise:Nothing

Posted 19 January 2012 - 01:21 PM

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?
0

#11 User is online   roothost 

  • Currently accepting new clients
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,463
  • Joined: 06-February 11
  • Reputation: 73
  • Gender:Male
  • Location:Lewes, East Sussex
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 19 January 2012 - 01:22 PM

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?
0

#12 User is online   MikeChipshop 

  • Small but imperfectly formed
  • Group: Moderators
  • Posts: 7,046
  • Joined: 19-April 10
  • Reputation: 503
  • Gender:Male
  • Location:Scotland

Posted 19 January 2012 - 01:23 PM

View PostSpitfire, on 19 January 2012 - 01:19 PM, said:

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?
0

#13 User is online   Spitfire 

  • Mighty Pirate™
  • PipPipPipPip
  • Group: Members
  • Posts: 891
  • Joined: 05-February 11
  • Reputation: 189
  • Gender:Male
  • Location:Berkshire
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 19 January 2012 - 01:30 PM

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

Ah well, just for all you OCD people out there here's the article I mentioned previously:
http://wp.tutsplus.c...-for-wordpress/
1

#14 User is online   MikeChipshop 

  • Small but imperfectly formed
  • Group: Moderators
  • Posts: 7,046
  • Joined: 19-April 10
  • Reputation: 503
  • Gender:Male
  • Location:Scotland

Posted 19 January 2012 - 02:20 PM

View PostSpitfire, on 19 January 2012 - 01:30 PM, said:

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.
0

#15 User is online   Renaissance-Design 

  • Available for custom WordPress work
  • View blog
  • Group: Moderators
  • Posts: 3,594
  • Joined: 12-August 10
  • Reputation: 559
  • Gender:Male
  • Location:South Wales
  • Experience:Web Guru
  • Area of Expertise:Designer/Coder

Posted 19 January 2012 - 03:05 PM

Here's my take: Loading JQuery from Google’s CDN with local fallback in WordPress.

Sorry it took so long.
2

#16 User is online   roothost 

  • Currently accepting new clients
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,463
  • Joined: 06-February 11
  • Reputation: 73
  • Gender:Male
  • Location:Lewes, East Sussex
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 19 January 2012 - 03:30 PM

View PostRenaissance-Design, on 19 January 2012 - 03:05 PM, said:


Nice tut Chris, many thanks for posting :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users