If you want to share front end functionality between Mendix apps or publish it to the store you will want to create a widget for it.
You can find a course on it Here and documentation Here .
Hope this helps
You could also try and use https://appstore.home.mendix.com/link/app/56/Mendix/HTML/-JavaScript-Snippet
This loads the javascript when calling the page, if you want it converted into a widget, see Dragos his post.