I was thinking if I can make a variable for the key and store it in another js but I don't know how can I insert in the src.
That's pointless. You'd still have to give it to the browser.
See API Key Best Practices:
To set an application restriction for an API key
- Visit the credentials panel.
- Select the API key that you want to set a restriction on. The API key property page appears.
- Under Key restrictions, select Application restrictions.
Select one of the restriction types and supply the requested information following the restriction list.
HTTP referrers
Accept requests from the list of websites that you supply.
Below the types, specify one or more referrer web sites. Wildcard characters are acceptable for naming similar web sites. For example, *.google.com accepts all sites ending in google.com, such as https://developers.google.com.