Viewing 4 replies - 1 through 4 (of 4 total)
  • Gareth

    (@catapult_themes)

    Okay – I’ll investigate.

    Thanks

    Gareth

    Hi,

    I was finding the same problem. Took a while to diagnose as sometimes JQuery loads up quick enough and the problem is avoided, but occasionally this does not happen and JavaScript stops processing with the same error you described. Most often was happening on this page for me, but not every time, around 1 in 10.

    Found the problem was not Cookie Consent and that jQuery was loaded with defer/async. Have removed that problem and now site working fine again, with latest versions of Cookie Consent and AutoOptimise.

    Found the cause in my theme functions, but could be a plugin, etc. Check the source of the page to see if jQuery has a Defer/Async and find the cause of this to see if it is the same problem as mine.

    Anthony

    Ant

    fyi; by default Autoptimize excludes js/jquery/jquery.js from JS optimization. If however:

    • jquery is removed from that list and/ or
    • jquery is loaded from another path and/ or
    • jquery is asynced or deferred

    Then indeed this will likely cause “jQuery is not defined” errors. The fix should be pretty easy (re-add it to the exclusion list, adapt path or don’t async/ defer).

    frank (ao dev)

    Thread Starter Clement Gonnet

    (@renoovodesign)

    Or an alternative would be to ensure the script loads only after jQuery is loaded. Maybe using dependencies.

    Does the script have to be in the footer? If it cannot be loaded using wp_enqueue_script where a dependency can be defined, then how about using the following:
    wp_add_inline_script( string $handle, string $data, string $position = 'after' );
    where $handle is ‘jquery’.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Inline JS not declared properly.’ is closed to new replies.