• Resolved LordBass

    (@lordbass)


    Hello,

    If jQuery is deferred, it’s not defined during the page load, which means the plugin will throw an error (“jQuery is not defined!”).

    I managed to add a quick hack for the code to work just by surrounding the code with a DOMContentLoaded listener:

    window.addEventListener('DOMContentLoaded', function() {
    //plugin js
    });

    This ensures the script runs after the DOM is loaded (which means deferred scripts were already executed). This is required to minimize render-blocking javascript.

    I’m wondering if it’s possible to add a similar fix into a future version.

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @lordbass,

    Thanks for the suggestion! I’ll try it out and if it passes my tests I may consider adding this change to the plugin.

    Have a nice day!

    I would like to throw in my 2 cents aswell.

    For some odd reason I cannot really explain the following happens;
    WPP with AJAX option on (as I am using caching etc);
    – Works in Chrome, Firefox, Opera, Firefox Dev edtion
    – Does not work in Mobile Safari, Safari and IE.

    In the not working browsers it throws a jQuery not defined notification. But I really can’t say why. I’ve tried a lot (disabling caching (Wp-Rocket), disbaling (Varnish (server side) etc.

    If I switch to the static function; it works in each and very browser but for the love of me i can not get it working cross-broswser with AJAX. If it did a fallback

    I made it work by making the widget area ajaxified using; https://www.ads-software.com/plugins/no-cache-ajax-widgets/
    Old but still does the trick.

    Any suggestions would be greatly appreciated to it without the addtional plugin though.

    Kind regards,
    Patrick Dankers

    Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @patrick_d1985,

    Hard to tell what’s happening on your case since I don’t own a Mac computer nor an iPhone to check how the widget behaves on Safari.

    I did test on IE11 and on Edge and the widget loads normally even with the Ajaxify widget option enabled – but of course I’m not deferring jQuery as the OP is (and I’m guessing you’re too?)

    Did you try LordBass’ workaround already?

    Hi Hector,

    thanks for getting back on this!

    Yeah it was weird for some odd reason in those browsers jQuery was not seen correctly at the moment WPP was fired. Doing some basic jQuery actions in the Developers console worked just fine actually.

    Yeah I am deferring jQuery. And my case might be a rough one due to the setup we use (Varnish caching, Nginx +PHP-FPM, HTTPS, HTTP2. Mod_pagespeed Wp-Rocket, Cloudflare, MaxCDN). Like I said it’s a bit of monster.

    So perhaps just something of that combo is causing some shifts in order things are done really. But I could not find out what.

    I tried the suggestion noted here but that did not help my situation. But the weird thing I concluded was; normal mode works fine, ajax mode did not cross browser. So then I decided ok what if I don’t let WPP itself do the AJAX call. Thats where the old No AJAX Widgets plugin came in.And that worked wonders.

    Just throwing that out as an option for people who just can not seem to get it to run.

    Hope it helps anybody though.

    Plugin Author Hector Cabrera

    (@hcabrera)

    Yeah, it does sound like a monster (and a complete PITA to maintain :P)

    If you’re willing to do one more test @patrick_d1985, let’s try using the load event instead:

    window.addEventListener('load', function() {
    //plugin js
    });

    Please let me know if it makes any difference.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Ajax not working on deferred jQuery’ is closed to new replies.