title: Spring mvc loading JS with Uncaught SyntaxError: Unexpected token <
body: <p>I'm using Spring boot. I have this structure for a simple test app:</p>
  
  <p><a href="https://i.stack.imgur.com/cD4Fk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cD4Fk.png" alt="enter image description here"></a></p>
  
  <p>What I do in my TestController is to get 2 path variables and load index.html:</p>
  
  <pre><code>@Controller
  public class TestController {
  
      @RequestMapping("/{vara}/{varb}")
      public String index(@PathVariable(value="vara") String vara, @PathVariable(value="varb") String varb) {
          return"/index.html";
      }
  }
  </code></pre>
  
  <p>and the index.html is empty, clean html page:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  TEST
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>so typing <strong>localhost:8080/abbas/mirza</strong> in my browser and everything looks ok and the html page loads easily. 
  I have 2 js files, <strong>test.js</strong> and <strong>/js/testb.js</strong> which both have this line of code inside.</p>
  
  <pre><code>var s = {}; 
  </code></pre>
  
  <p>Now I add this </p>
  
  <pre><code>&lt;script src="/test.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>and everything is still ok  and I can view the test.js code, but when I add </p>
  
  <pre><code>&lt;script src="/js/testb.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>the page throws an exception </p>
  
  <pre><code>Uncaught SyntaxError: Unexpected token &lt;
  </code></pre>
  
  <p>and when I try to open the testb.js file it shows me this</p>
  
  <p><a href="https://i.stack.imgur.com/x8MD9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x8MD9.png" alt="enter image description here"></a></p>
  
  <p>if I move testb.js into the webapp itself, it will be loaded with no problem. I'm quite newbie using the Spring mvc and still confused with all the configuration regarding routings and accessing resources. </p>
  
  <p>Any idea what I'm doing wrong?</p>
  
  <p><strong>Edit:(link to github)</strong> <a href="https://github.com/arashzz/test22" rel="nofollow noreferrer">https://github.com/arashzz/test22</a></p>