How to call custom javascript function defined in js file from .module file
I have faced same kind of issue few days ago and I have resolved it by adding type as module to the script tag. All script with type=module have differ attribute. It download such js parallel with loading of other page and then run them in order but after the parsing is done.

This might help you:

&lt;script language='javascript' type='module'&gt;