• Resolved polymathy

    (@polymathy)


    Hello,

    for some reason I get this error in the console of Chromes Dev Tools, with the plugin enabled:
    An error has occurred: jQuery is not defined

    I tried the option “Skip deferring the jQuery library”, but that didn’t help. I also tried putting the jQuery file on the ignore list like so:
    /wp-content/themes/acabado-child/js/jquery-3.4.1.min.js

    and checking in the settings “Skip deferring the ignore list” in the settings, but that also didn’t work. I tried it with both, hosting jQuery on my on server and also getting it via CDN (which was the default).

    What did help was either the option “Disable JavaScript processing” or disabling the plugin as a whole, so it definitely has to do something with the plugin.

    I would like the plugin to optimize my JS and just leave jQuery untouched, but it doesn’t seem to work.

    This is my site: maehroboter-guru.de

    • This topic was modified 4 years, 9 months ago by polymathy.
    • This topic was modified 4 years, 9 months ago by polymathy.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Raul P.

    (@alignak)

    Do you have a good reason to include jquery v3?
    Wordpress already has a jquery version, so by using v3 you risk some plugins not being compatible.

    The “Skip deferring the ignore list” only works for the default jquery file on wordpress. The ignore list should work for any file that it’s been merged and you don’t want it to be.

    If some js files are not being merged, there is no need for the ignore list.
    It means that you haven’t enqueued them properly, usually, so FVM cannot detect them.

    Merging scripts, means they have to move somewhere.
    Usually header or footer.
    There is also a difference between defer and async.
    Defer makes it that they load after page load.
    If you have some code that requires render blocking, it’s going to be undefined because it hasn’t load yet.

    If you have jquery undefined, your jquery must somehow be loading too late.

    I see you are using:
    <script type='text/javascript' async defer src='https://www.maehroboter-guru.de/wp-content/themes/acabado-child/js/jquery-3.4.1.min.js'></script>

    Loadind scripts Async means, you are telling the browser, that’s it’s ok to load jquery anytime, either early or later, so it makes sense that in some cases, it loads after page load and thus jquery is undefined.

    This means your site needs jquery to be render blocking.
    It may work when async, because jquery is the first script on your page and it loads early, or it’s cached. However, it’s not guaranteed that it will always work for all users.
    https://stackoverflow.com/questions/10808109/script-tag-async-defer

    You should only use async for scripts that are completely independent, such as ads.
    Many plugins depend on jquery, so unless all code is deferred as well, you cannot remove the dependencies by forcing wordpress to load jquery async.

    You may have some other plugin causing conflicts when merged.

    Please note that this plugin is for developers and advanced users, so you have to be able to understand how some of these things work or hire someone.

    There are some faqs to help you solve the issues:
    https://www.ads-software.com/plugins/fast-velocity-minify/faq/

    If that doesn’t work, you will need to have a developer fix your theme modifications first and do some manual work.

    Thread Starter polymathy

    (@polymathy)

    Thank you for your detailed answer. It helped me understand more about the problem.

    The parent theme I’m using seems to be causing some issues, which makes it not work well with the JS handling of FVM. Namely, it deregisteres “jquery” (which is why I reregistered another version) and it also puts the “async defer” in any added JS script, so it also puts it on my registered version of jQuery.

    My theme and FVM seem to not work well together. I’m aware that the theme I’m using is not super professionally made and doesn’t meet all the standards, but I can only use this one, because it’s specially made for my purpose. So I’ll simply deactivate the JS handling completely by FVM, I guess that should work for now.

    Plugin Author Raul P.

    (@alignak)

    Then perhaps, disabling that option that adds async defer to all scripts, should work.
    FVM already does that for merged scripts.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘jQuery not defined’ is closed to new replies.