• Resolved SimonNo

    (@simonno)


    Hello i’m using a custom javascript function added via wp_enqueue only on one page (via is_page()) .

    With Autoptimize active, only the function is only executed after onclick.

    But the part, that calls the function on page load is not working.

    [code language="javascript"]
    document.addEventListener("DOMContentLoaded", selectVersion(), false);
    [code]

    If i excluce the whole script from AO, everything works like it should.

    Do you know why this problem occurs?

    Thank you and best regards
    Simon

    • This topic was modified 6 years, 4 months ago by SimonNo.
    • This topic was modified 6 years, 4 months ago by SimonNo.
    • This topic was modified 6 years, 4 months ago by SimonNo.
    • This topic was modified 6 years, 4 months ago by SimonNo.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    Probably because the optimized JS is deferred, so it loads after the DomContentLoaded fired and your event listener is never triggered.

    hope this clarifies,
    frank

    Thread Starter SimonNo

    (@simonno)

    Thank you very much for your reply! I’m going to try a different event then!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Javascript Function’ is closed to new replies.