title: How to inject script with relative path to html using javascript
body: <p>I've got a problem when I was trying to inject script to html page using javascript. This script have to be set with relative path just like it was into my cshtml file:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
  &lt;head&gt;
      @{
          if (Request["debug"] != "false")
          {
              &lt;script src='~/Scripts/script-first-debug.js'&gt;&lt;/script&gt;
              &lt;script src='~/Scripts/script-second-debug.js'&gt;&lt;/script&gt;
          }
          else
          {
              &lt;script src='~/Scripts/script-first.js'&gt;&lt;/script&gt;
              &lt;script src='~/Scripts/script-second.js'&gt;&lt;/script&gt;
          }
      }
  
  &lt;/head&gt;
  &lt;body&gt;
      @RenderBody()
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and it's part of my typescript file where I moved this .net case from cshtml file:</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>On localhost everything is good but when this code has been deployed on my production instance of application then I've got a problem. On my production application instance I add to address some string. For example:</p>
  
  <p>On localhost the path to script-first.js is: <a href="https://localhost:80/Scripts/script-first.js" rel="nofollow noreferrer">https://localhost:80/Scripts/script-first.js</a></p>
  
  <p>On production the path to this file is like that:
  <a href="https://www.myproblematicapplication.com/someString/Scripts/script-first.js" rel="nofollow noreferrer">https://www.myproblematicapplication.com/someString/Scripts/script-first.js</a></p>
  
  <p>Have you got any tips how can I to do it?
  I was trying to find some solutions on stack overflow and on other pages but unfortunetly without success yet.</p>