• Resolved pepe80

    (@pepe80)


    I am using Contact Form 7 forms on the website and they stopped working when I turned the option:
    Page Optimization -> Load JS Deferred -> Delayed
    When I submit the form, the page reloads instead of making the request in the background (ajax). Most likely, this is because the cf7 script (https://github.com/takayukister/contact-form-7/blob/master/includes/js/index.js) configures forms in response to an DOMContentLoaded event.

    I know I can exclude cf7 scripts (Tuning -> JS Deferred Excludes):
    wpcf7 (variable definition inline script)
    /contact-form-7/includes/js/index.js

    I wonder if there is some way to deal with the scripts that listen to DOMContentLoaded event. I could manually trigger an event in a script that is loaded at the very end:

    window.document.dispatchEvent(new Event(“DOMContentLoaded”, {
    bubbles: true,
    cancelable: true
    }));

    …but I am concerned about how scripts that are excluded from delayed loading and are also based on this event will behave (double triggering DOMContentLoaded event)

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support qtwrk

    (@qtwrk)

    Hi,

    unfortunately that’s the only option we have so far to deal such kind of issue

    Best regards,

    Thread Starter pepe80

    (@pepe80)

    Hi @qtwrk,
    thank you for your answer. I wonder how the nitropack.io plugin is dealing with this problem. Here is example (cf7 + Load JS Deferred):
    https://ckadn.pl/kontakt/

    When I type on the dev console:
    getEventListeners(document);
    …I see:
    – DOMContentLoaded
    – DOMContentLoadedNitro <– that could be crucial

    Plugin Support usabe

    (@usabe)

    Hi @pepe80

    Thank you for the referring info.

    Since lscwp and nitropack had different focus and strategies, and lscwp has already provided the exclusion mechanism as solution for such issue, I don’t think we will put this in a higher priority in short term. But we’ll keep it in mind and check into this to see what we may do better in future.

    Best regards,
    Abe

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Load JS Deferred (Delayed) and broken scripts like CF7’ is closed to new replies.