title: Script version number causes undefined variables
body: <p>I have a javascript file that is loaded with a version parameter, to cause it to reload every time I change it.</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;script type="module" src="js/main.js?20190327-1"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>Sometimes I try to access a variable and I get an undefined error. I print the variable to the console and I have the following result (Line 703 is the set of the variable and line 279 is the get):</p>
  
  <p><a href="https://i.stack.imgur.com/3qk8x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3qk8x.png" alt=""></a></p>
  
  <p>I called the same thing twice and the second time it seems to work. What I noticed is that it changes the file name from "main.js" to "main.js?20190327-1".</p>
  
  <p>I removed the version from the src and it seems to work fine.
  <a href="https://i.stack.imgur.com/tFqgE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tFqgE.png" alt=""></a></p>
  
  <p>Am I missing something with the usage of the version parameter? Is there any other way I could force the browser to reload the scripts every time a version is changed?</p>
  
  <p>Thank you in advance.</p>
  
  <hr>
  
  <p>edit:
  I found out that the problem was caused by both loading as a script</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;script type="module" src="js/main.js?20190327-1"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>but also importing it as a module from javascript code.</p>
  
  <pre><code>import * as main from './js/main.js'
  </code></pre>
  
  <p>That caused the browser to load it twice. If I rename all occurrences of
  <code>import * as main from './js/main.js'</code> to <code>import * as main from './js/main.js?20190327-1'</code> everything works fine. But is there any way to force it to reload without the need to rename all the imports?</p>