function ready(fn) {
    // Checking readyState here is a failsafe in case the htmx script tag entered the DOM by
    // some means other than the initial page load.
    if (isReady || getDocument().readyState === 'complete') {
      fn()
    } else {
      getDocument().addEventListener('DOMContentLoaded', fn)
    }
  }
Execute a function now if DOMContentLoaded has fired, otherwise listen for it.

This function uses isReady because there is no reliable way to ask the browser whether
the DOMContentLoaded event has already been fired; there's a gap between DOMContentLoaded
firing and readystate=complete.