Load order of scripts

Community Forums Forums General Discussion Load order of scripts

This topic is: not resolved

Tagged: 

This topic contains 8 replies, has 2 voices, and was last updated by  David Chu 1 year ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #47787

    Natalie
    Participant
    Post count: 11

    Genesis newbie here so be gentle. I’m running into a peculiar issue. Not sure if it’s a bug in 2.0 or intended. I’m trying to use fittext.js on a site using Genesis 2.0 Beta and it’s sample child theme. It looks like jQuery is being loaded in the footer, but any scripts I add to the footer via the Theme Settings are output before any other scripts. So basically, nothing requiring jQuery gets run because it’s called before jQuery loads. I’ve managed to get fittext.js working by adding jQuery into the Theme Settings, but that doesn’t seem ideal. Anyone know if that’s normal behavior, to load user scripts BEFORE jQuery or did I stumble across a bug?

    #47795

    David Chu
    Participant
    Post count: 1316

    Hi,
    For a newbie you know a lot more than most, so no worries and welcome!

    I like using that handy spot to add my custom jQuery goodies, too. But if you’d like to try to load it elsewhere, I would suggest having a look at this scenario or this one. They should get you pointed in the right direction. The idea is to use wp_enqueue_script in your theme’s functions.php.

    Hope that helps,
    Dave


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

    #47798

    Natalie
    Participant
    Post count: 11

    Thanks! I actually used the de-register script from the second link you posted so jQuery wasn’t loaded twice. I tried enqueueing fittext via functions (using the handy script generator at http://www.bensmann.no/downloads/wordpress-enque-script-generator/) but it did the same thing as if adding it via the Theme Settings…it added it before jQuery.

    It seems like any script the user adds in the footer should be the last thing output just before the </body>. I’m curious if this is a new issue because the post you referenced above that I used to de-register jQuery says Genesis loads jQuery in the header by default. That’s doesn’t seem to be the case with 2.0.

    #47801

    David Chu
    Participant
    Post count: 1316

    Great!
    I think you’re ahead of me on this issue… I haven’t had time to use 2.0 yet, although before I had done some experiments getting HTML5 into 1.9. And now WP comes with its own jQuery, of course, but I haven’t had enough problems with plugins and such to investigate the loading order much. I had done more loading order experiments with bits of custom CSS.

    Maybe some early adopters will chime in with newer and more germane info!

    Dave


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

    #47815

    David Chu
    Participant
    Post count: 1316

    Hi!
    I took some additional interest in this, and peeked at 2.0 on my local server. I jury-rigged 2.0 beta so that I could have 1.9 in the same installation, as well as the 2.0 beta Sample Theme. :-) It worked nicely.

    I had jQuery loading, but not in the footer, it was up in the header where I expected it. Then I disabled all plugins, and jQuery was no longer loaded, which made sense, why load it if not needed. I also saw the demo 2.0 page elsewhere that didn’t load jQuery.

    I wonder if some errant plugin is loading jQuery in your footer. I’m not a world authority on jQuery, but I can’t see any normal reason for loading it in the footer either. You want to have that baby available for any scripting that happens further down in the header or anywhere else where you may need it, like in, well, the footer. :-)

    PS: the only hiccup I found so far in my jury-rigged setup was that when I tried to re-enable Genesis plugins, they balked, saying that Genesis wasn’t installed. Busted! That’s why it’s great to have a test bed. :-)

    Dave


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

    #47861

    Natalie
    Participant
    Post count: 11

    Thanks for all the help. I’m not sure I completely follow though. Does Genesis somehow detect when something needs jQuery in order to load it? Makes sense not to load if unnecessary but at what point does Genesis load it? How can I tell if it’s Genesis loading it or a plugin?

    FYI – I found 2 plugins (Gravity Forms and Leaflets Map Marker) that when activated separately result in the jQuery script being loaded…both in the same place in the footer (just after an admin-bar js file).

    #47863

    David Chu
    Participant
    Post count: 1316

    Not my exact jurisdiction, either. I’d have to say that plugins are probably loading jQuery, no magic detection.

    How can you tell? You could do like I did, and disable plugins one by one until it vanishes, then you have the smoking gun. :-)

    The Genesis big honchos are pretty active on Twitter and don’t hang out here much. A quick Tweet to them could get your question answered.

    Also, though documentation is better all the time here, ultimately I think you’ll fare best if you do as I do, get a code scanner, and keep that baby trained on the Genesis code. :-) I find cool functions that aren’t widely publicized, and answers to anything obscure. And scan the plugins, too.

    D


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

    #47864

    Natalie
    Participant
    Post count: 11

    What’s a code scanner?

    #47874

    David Chu
    Participant
    Post count: 1316

    I used a vague term…. it’s just any application that can scan files for text strings, filenames, and so on. There are loads of them.


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.