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](https://www.drupal.org/docs/8/theming-drupal-8/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-theme).