Load custom javascript in cib seven webapp

Hi,

I would like to load a custom JavaScript file from our CIB seven theme into the webapp frontend.

At the moment I use the following workaround.

I modify this file on the application server

/opt/cib/server/apache-tomcat-10.1.47/webapps/webapp/WEB-INF/classes/public/assets/i18n-CiT0mRgf.js

and append this code at the end of the file

var s = document.createElement("script");
s.src = "/cib/themes/themename/custom.js";
s.async = true;
s.onload = function () {
  console.log("custom.js wurde erfolgreich geladen");
};
s.onerror = function () {
  console.warn("custom.js konnte nicht geladen werden");
};
document.head.appendChild(s);

Is there an official or recommended way to load custom JavaScript from a theme in the CIB Seven frontend?