$(document).ready(function(){somefunk_from_external_script();});
OK i am having one heck of a time. I have spent weeks looking for any accurate documentation on Magento2 modules. A few exist but they dont cover how i might get something as simple as the above code.
Feel free to point me to some seemingly obvious answer but i really need to have it wait till the entire DOM is loaded. This wouldnt be an issue but Magento2 seems to load JS files before HTML
I recommend to place your initial JavaScript into x-magento-init: https://mage2.pro/t/145
Then, you can load other JavaScripts as AMD modules using RequireJS: https://mage2.pro/t/141
I recommend to use the the domReady! dependency in an AMD module to ensure the DOM is loaded: https://mage2.pro/t/540
No good. I have resolved to checking for an element to exist and if not aborting to call. The code just keeps getting called until the page does load. I wonder why Magento developers assume everyone understands their API. I wonder if posting meaningful documentation for single developer shops is being withheld to extort training fees?. To do anything in Magento 2 it seems you must resolve to reverse engineer. but this is a very incomplete tactic. Every other ecom and cms has extensive straight forward documentation. Why is it so hard to do the simple stuff