- This topic is empty.
-
AuthorPosts
-
July 8, 2013 at 9:38 am #46206Ricky55Member
I’m enqueuing a copy of jQuery into my theme. Is it best to load jQuery in the head or the footer?
On static sites I always go for footer but for plugin compatibility etc is it best to go with the head?
July 8, 2013 at 9:45 am #141905SenffParticipantLoad library in the header, and your custom functions in the footer.
July 8, 2013 at 11:33 am #141918Ricky55MemberCheers man!
Is that due to plugins etc using the wp-head hook to insert their scripts
July 8, 2013 at 11:33 am #141919Ricky55MemberAlso, am I best just using the version of jQuery that comes with WP?
July 8, 2013 at 11:51 am #141921SenffParticipantYour custom functions should come as late as possible, to make sure that the library and all HTML has loaded. It’s not just for WordPress, you should always do this with any site.
There’s various ways of loading the library: your own local one, the WP one, a CDN one…all have their pros and cons. I personally always use the one that comes with WP but that’s only because I’m lazy. :)
July 8, 2013 at 1:24 pm #141930Ricky55MemberI realise this that’s why I personally always load jquery just before the close of the body but I thought doing this with WP could be risky if plugins that rely on jquery were being loaded into the head I.e before jquery.
So my final question do you load jquery in the head or before the close of the body?
Cheers
July 8, 2013 at 2:02 pm #141932TheDocMember> Your custom functions should come as late as possible, to make sure that the library and all HTML has loaded. It’s not just for WordPress, you should always do this with any site. @Senff
I always load libraries at the bottom. The only thing that gets loaded in the `
` in my projects is Modernizr. Everything else (jQuery, plugins, site.js, etc) get loading just before the closing ``.July 8, 2013 at 2:13 pm #141934TreeRootParticipantI too prefer @TheDoc approach. I use this technique to load jQuery at the bottom:
http://beneverard.co.uk/blog/wordpress-loading-jquery-correctly-version-2/Then I brute force any plugins that register scripts in the head to move to the footer, below jQuery:
http://www.kevinleary.net/faster-wordpress-move-javascript-files-footer/July 9, 2013 at 8:43 am #142001Ricky55MemberThanks guys, I must admit I didn’t like loading scripts in the head just seems plain wrong.
-
AuthorPosts
- The forum ‘Other’ is closed to new topics and replies.