Skip to content

addEventListener("DOMContentLoaded", ...) never runs? #87

Closed

Description

Activity

  1. niutech commented on Oct 7, 2020

    @niutech
    Collaborator

    This is because the scripts are being fetched and run after DOMContentLoaded event, so the solution is to use load event instead or check if DOMContentLoaded event has been fired:

    if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', main); else main();
  2. jason-s commented on Oct 7, 2020

    @jason-s
    Author

    Nope, then the solution is to use another service then.

    This is a bug.

    Rawgit.org works fine: https://ghcdn.rawgit.org/jason-s/embedded-blog-public/master/demos/gravity1/gravity1.html

  3. niutech commented on Oct 7, 2020

    @niutech
    Collaborator

    Rawgit is a third-party proxy server and could theoretically shut down at any time, while HTMLPreview is a client-side project without third-party servers (with an exception of external JS/CSS scripts, which are being proxied due to CORS). Because of this, the scripts are deferred and run past the DOMContentLoaded event. I can experiment with manually dispatch DOMContentLoaded event, but I am afraid this could have side effects on existing scripts (double dispatch).

  4. reopened this on Oct 7, 2020
  5. max-hk commented on Oct 12, 2020

    @max-hk

    How about running all functions returned from getEventListener(document).DOMContentLoaded?

  6. niutech commented on Oct 13, 2020

    @niutech
    Collaborator

    @MaxLOh Do you mean getEventListeners()? It's only in Chrome DevTools. But I can manually dispatch DOMContentLoaded event like this: document.dispatchEvent(new Event('DOMContentLoaded', {bubbles: true, cancelable: true}));, although it may have side effects, which I wrote above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions