If your component is always used, just move the inclusion of javascript into the rendering layout in your view.yml application:
default: javascripts: [my_js]
There is no need to separate the JS call when it is always in use.
UPDATE:
If you need to support the inclusion of JS with a component, you can put your component call in the slot before calling include_javascripts() to add it to the stack that will be displayed, and then enable the slot in the right place:
<?php slot('nav') ?> <?php include_component('nav', 'nav'); ?> <?php end_slot(); ?> <html> <head> <?php include_javascripts() ?> ... </head> <body> <?php include_slot('nav'); ?> <?php echo $nav ?> ... </body> </html>
source share