Calling code from a single Javascript file instead of calling intepedent Javascript files

I use a cookie consent policy banner from https://www.freeprivacypolicy.com which calls JS script files according the category they belong.

Fore example:
<script type="text/plain" cookie-consent="tracking" src="google-analytics.js"></script>
is called when users enable tracking cookies and
<script type="text/plain" cookie-consent="targeting" src="google-adsense.js"></script>
is called when users enable targeting cookies related to advertisement.

Is it possible to put all the relevant Javascript code in one file and instead of calling certain files according to the users’ preferences to call the relevant functions in their place? Or is using separate files the only possible way of implementation?