title: How can I load .wasm files stored in a subdirectory?
body: <p>I am trying out a simple example to call a C function compiled to .wasm with JavaScript. </p>
  
  <p>This is the <code>counter.c</code> file:</p>
  
  <pre><code>#include &lt;emscripten.h&gt;
  
  int counter = 100;
  
  EMSCRIPTEN_KEEPALIVE
  int count() {  
      counter += 1;
      return counter;
  }
  </code></pre>
  
  <p>I compiled it using <code>emcc counter.c -s WASM=1 -o counter.js</code>.</p>
  
  <p>My <code>main.js</code> JavaScript file:</p>
  
  <pre><code>Module['onRuntimeInitialized'] = onRuntimeInitialized;
  const count = Module.cwrap('count ', 'number');
  
  function onRuntimeInitialized() {
      console.log(count());
  }
  </code></pre>
  
  <p>My <code>index.html</code> file only loads both .js files in the body, nothing else:</p>
  
  <pre><code>&lt;script type="text/javascript" src="counter.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="main.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>It works fine / prints 101 to the console, <strong>but when I move the <code>counter.c</code> file to a <code>wasm</code> subdirectory</strong>, recompile it with emscripten and update the <code>script</code> tag to <code>src="wasm/counter.js"</code>, the <code>counter.js</code> script tries to load <code>counter.wasm</code> from the root directory instead of the <code>wasm</code> subdirectory and I get the error:</p>
  
  <p><code>counter.js:190 failed to asynchronously prepare wasm: failed to load wasm binary file at 'counter.wasm'</code></p>
  
  <p>I did some research, but I didn't find any way to tell emscripten to let the generated .js file load the .wasm from the same subdirectory.</p>