Encountering an issue while attempting to inject a script into an HTML page using JavaScript. The script needs to have a relative path similar to what is in the cshtml file:
<!DOCTYPE html>
<html>
<head>
@{
if (Request["debug"] != "false")
{
<script src='~/Scripts/script-first-debug.js'></script>
<script src='~/Scripts/script-second-debug.js'></script>
}
else
{
<script src='~/Scripts/script-first.js'></script>
<script src='~/Scripts/script-second.js'></script>
}
}
</head>
<body>
@RenderBody()
</body>
</html>
This is a snippet of my TypeScript file where I have moved this .NET logic from the cshtml file:
var scriptFirst = document.createElement('script');
var striptSecond = document.createElement('script');
scriptFirst.type = 'text/javascript';
striptSecond.type = 'text/javascript';
scriptFirst.src = this.debug ? '/Scripts/script-first-debug.js' : '/Scripts/script-first.js';
striptSecond.src = this.debug ? '/Scripts/script-second-debug.js' : '/Scripts/script-second.js';
$('head').append(scriptFirst).append(striptSecond);
Everything works fine on localhost, but when I deploy this code to my production application instance, I encounter an issue. The production application adds some string to the address. For example:
On localhost, the path to script-first.js is: https://localhost:80/Scripts/script-first.js
On production, the path to this file becomes:
Any suggestions on how to handle this issue? I've searched for solutions on Stack Overflow and other platforms without much success so far.