How do I change the javascript loading order
To add a js library to the header, define your library in my_module.libraries.yml with the header: true property.

my_library:
  header: true
  etc ...


Any dependencies defined for your library will always be loaded before your library whether loading your js in the header or footer.

See Asset loading order section here.