BigPipe messing up JS, is there a BigPipe ready() equivalent function? I'm experimenting with BigPipe on D8 and it seems that the regular jQuery $(document).ready() function fires before the BigPipe has finished loading all the elements causing quite a few difficulties.

For instance I have buttons with activation trigger element ID's which are loaded into a variable, but the trigger elements don't seem to get loaded by the time JS runs and they aren't present yet,breaking the functionality.

Is there a simpler workaround than rewriting all the JS libraries I'm using, that rely on the ready() function? Maybe something BigPipe specific solution I haven't found yet?
You must not ever rely on document.ready when you write js for drupal. You should use drupal behaviours; If used properly this will ensure that your code runs both on normal page loads and when data is loaded by AJAX (or BigPipe!)

Also read this interesting post on drupal issue queue JS relying on document.ready event does not work with BigPipe