Newsletter subscriber Vijay Rudraraju asked me how you would do this with WordPress. Great question!
In WordPress, you normally use
wp_enqueue_script() to load your JS files as an external file. We instead want to add
loadJS and our feature test inline in the footer, and call our external file with it.
This is definitely not the WordPress way of doing things, by the way. By not using
wp_enqueue_script(), the file never gets registered and can’t be called as a dependency by other scripts. However, if you’re writing vanilla, dependency-free scripts, it’s typically not a problem.
Here’s the code you would use to make it all happen…