Support » Plugin: Responsive Menu » Unnecessary enqueuing of jQuery

  • Resolved KTS915

    (@kts915)


    I notice that, on lines 38 to 41 of /config/wp/scripts.php you are enqueuing jQuery. There’s no need for that. WordPress does it automatically.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Peter Featherstone

    (@peterfeatherstone-1)

    Hey there,

    Is there any harm in doing it again to 100% ensure it’s loaded. I prefer my dependencies to be explicit rather than implicit and WordPress is clever enough to only load it once.

    Please let me know.

    Peter

    So you are happy to rely on WordPress being “clever enough to only load it once,” but you won’t rely on WordPress to load it in the first place?

    That makes absolutely no sense at all.

    Code bloat is already one of the problems of using WordPress. I don’t want to see anyone exacerbate it. I certainly hope no other developers start doing this.

    Plugin Author Peter Featherstone

    (@peterfeatherstone-1)

    Hi there,

    We will have to agree to disagree on this.

    I don’t see it as code bloat at all and do see it as making complete sense. It’s one line to maintain explicitness which I value more.

    Thank you

    Peter

    Plugin Author Peter Featherstone

    (@peterfeatherstone-1)

    Hey again,

    Can you let me know when WordPress started including jQuery by default as it wasn’t always this way.

    I wouldn’t want to break backwards compatibility.

    Peter

    I didn’t say that WP loads jQuery automatically everywhere. The right way to call jQuery is as a dependency when you enqueue your own scripts.

    That way, jQuery will load when you need it, but not when you don’t (unless it’s being called by something else, of course).

    Plugin Author Peter Featherstone

    (@peterfeatherstone-1)

    Hey again,

    Ah right ok now I understand what you mean and yes you are right about that.

    I will update accordingly and thanks for pointing that out 🙂

    Peter

    Great — thanks!

    Plugin Author Peter Featherstone

    (@peterfeatherstone-1)

    Hey again,

    I just remembered why I can’t do it this way.

    My plugin doesn’t use an external script by default so I do need to ensure jQuery is enqueued.

    I knew there was a reason it was there.

    Hope that helps

    Peter

    One of the things I like about your plugin is that I can use it without having to connect to an external resource. I don’t use any plugins that depend on external resources.

    But your reasoning is faulty, I’m afraid. The only circumstance in which you wouldn’t enqueue a script with a dependency is where you’re loading it inline.

    You’re not doing that at all. You’re just using your own scripts that you have bundled with the plugin. They still need to be enqueued in the usual way.

    Plugin Author Peter Featherstone

    (@peterfeatherstone-1)

    Hi there,

    I’m afraid that’s incorrect.

    The default behaviour is that it uses inline scripts and for that reason I do need to enqueue jQuery explicitly as you stated above.

    There is functionality in the plugin to load the scripts inline or as external files as a customisable option.

    I hope that helps clear it up.

    Peter

    You’re using inline scripts for the default? Wow, I am surprised. In that case, you are indeed correct and I am sorry to have troubled you.

    Plugin Author Peter Featherstone

    (@peterfeatherstone-1)

    Hi there,

    Yes that is correct but it is very much recommended to turn on the Use External Files option as per the doc page below:

    https://responsive.menu/docs/initial-setup/recommended-options/

    As with everything in the plugin it is fully customisable and this is a widely used option.

    Thanks again and have a good day.

    Peter

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Unnecessary enqueuing of jQuery’ is closed to new replies.