Reputation: 799
I am trying to load different JS file in Angular for different environment because the prefix for my js file is different and I can't save them in my local.
in dev
js file path is http://myproject-dev.com/product.js
so my html will be like
<script src="http://myproject-dev.com/product.js"></script>
prod
js file path is http://myproject.com/product.js
my html is like
<script src="http://myproject.com/product.js"></script>
I need to load them based on the environment, I have a variable set in JS to detect the environment but I don't know how to load them in html or in run time in Angular. Any tips will be appreciated. Thanks!
Upvotes: 1
Views: 111
Reputation: 64853
You can simply use relative paths to reference your files rather than using the full URL.
if you directory structure looks like this:
then inside of index.html you can reference product.js like this:
<script src="js/product.js"></script>
Upvotes: 2
Reputation: 616
Use a relative URL.
Same position: <script src="product.js"></script>
.
With a subfolder from current position: <script src="scripts/product.js"></script>
With a subfolder from root: <script src="/scripts/product.js"></script>
Upvotes: 2