ARTICLE AD BOX
In my application I have a couple of scripts, common and page-specific ones.
<head> <script type="text/javascript" src="/javascripts/menu.js"></script> <script type="module" src="/javascripts/index.js"></script> </head> # menu.js, loaded on each page document.addEventListener('DOMContentLoaded', () => { document.querySelector(".navbar-menu").addEventListener('click', () => { ... }); }) # index.js, page specific const { httpConstants, some more } = (await axios.get('/some-data')).data; document.addEventListener('DOMContentLoaded', () => { ... do other stuff for this side })The second part is never executed, obviously DOMContentLoaded is triggered only once. Before I was using jQuery and it was no problem to have jQuery(function () {... multiple times.
How is it done in Vanilla JS? How do I ensure the second script is running after DOM is loaded completely?
My first idea was to put dispatchEvent(new Event('DOMContentLoaded')) at the end of the first part. But then I get error InternalError: too much recursion.
