- This topic is empty.
July 8, 2013 at 9:38 am #46206
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 #141905SenffParticipant
Load library in the header, and your custom functions in the footer.July 8, 2013 at 11:33 am #141918
Is that due to plugins etc using the wp-head hook to insert their scriptsJuly 8, 2013 at 11:33 am #141919
Also, am I best just using the version of jQuery that comes with WP?July 8, 2013 at 11:51 am #141921SenffParticipant
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.
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 #141930
I 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?
CheersJuly 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 #141934TreeRootParticipant
I too prefer @TheDoc approach. I use this technique to load jQuery at the bottom:
Then I brute force any plugins that register scripts in the head to move to the footer, below jQuery:
Thanks guys, I must admit I didn’t like loading scripts in the head just seems plain wrong.
- The forum ‘Other’ is closed to new topics and replies.