Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other WordPress and jQuery

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #46206
    Ricky55
    Member

    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?

    #141905
    Senff
    Participant

    Load library in the header, and your custom functions in the footer.

    #141918
    Ricky55
    Member

    Cheers man!

    Is that due to plugins etc using the wp-head hook to insert their scripts

    #141919
    Ricky55
    Member

    Also, am I best just using the version of jQuery that comes with WP?

    #141921
    Senff
    Participant

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

    #141930
    Ricky55
    Member

    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?

    Cheers

    #141932
    TheDoc
    Member

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

    #141934
    TreeRoot
    Participant

    I 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/

    #142001
    Ricky55
    Member

    Thanks guys, I must admit I didn’t like loading scripts in the head just seems plain wrong.

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