<link rel=preconnect crossorigin=anonymous href="https://api.example.com">
or
<link rel=preload crossorigin=anonymous href="https://api.example.com/emptyendpoint">
just to initiate the connection/CORS dance early one before your JS kicks in. In my prev job we'd do a request to empty endpoint from inlined JS. Poor hack but it worked.