title: Loading javascript dynamically based on the http or https protocol
body: <p>I have a javascript file located in a different server, and I am including the javascript file over <code>http</code> page like</p>
  
  <pre><code>&lt;script type="text/javascript" src="http://www.example.com/scriptfile.js"&gt;
  </code></pre>
  
  <p>or over <code>https</code> page like</p>
  
  <pre><code>&lt;script type="text/javascript" src="https://www.example.com/scriptfile.js"&gt;
  </code></pre>
  
  <p>The problem is, that I have page switching from <code>http</code> to <code>https</code>, for example, if a user is in</p>
  
  <p><code>http://www.example.com/home</code>(site home URL) and I load the javascript over <code>http</code>, now when the user navigates to another page like <code>https://www.example.com/transaction</code> (site transaction URL), I load the script over <code>https</code> and its working fine. From the mentioned transaction URL if the user hits the <code>https://www.example.com/home</code> (home URL changed to <code>https</code>), the script which I loaded over <code>http</code> fails because of unsecured content. Any suggestion to handle this is welcomed.</p>