Making sure that the javascript file is loaded first

Hey!

I have yet another app idea and it would require loading&executing a tiny javascript polyfill before any other javascript is executed on the website.
I imagine it should be a straightforward process of adding the file just after the tag on the app activation. But then I am sure that there are plenty of apps that do the same thing.

How could I make sure that my script stays at the top at all times? Is there a webhook that informs about new app activation? Or a .liquid file change?

Thanks,
Tadas

As an app developer there’s no way for you to make sure of that unless you’re the person in control of the website source code, in which case you’d add it directly to layouts/theme.liquid.

P.S. yes there is a themes/update webhook available, but if you’re auto-injecting your code it won’t be right after the head anyway. At best it might be the first script where ever the theme developer put {{ content_for_header }} which is what populates theme scripts in the head.