title: How to handle paths of JS and CSS in Golang Templates
body: <p>currently am working in a Golang Site, as frontend I am using the go templates. In order to separate the different parts of the sites I created this templates:</p>
  
  <ol>
  <li>Head: containing the <code>&lt;head&gt;</code> tag, and some imports of css</li>
  <li>Header: defining the navbar of the site, logo, etc. It's only HTML </li>
  <li>Footer: defining the HTML of the footer of the site. </li>
  <li>SomePage: defining the body tag, this template calls Head, Header and footer. This file can be for example the index, the login, etc.</li>
  </ol>
  
  <p>I added the Javascript imports just after I nest the footer template, but still inside the body tag. As example, I added them like:</p>
  
  <pre><code>&lt;script src="public/js/SomeJS.js"&gt;&lt;/script&gt;
  &lt;link href="public/css/SomeCSS.css" type="text/css" rel="stylesheet"/&gt;
  </code></pre>
  
  <p>In the routes of my project I have defined <code>public</code> to serve those static files, this is working pretty nice. Now, I have some routes of the project, lets say:</p>
  
  <pre><code>router.GET("/",controllers.Index)
  router.GET("/login",controllers.Login)
  </code></pre>
  
  <p>With the first route, the libraries are being loaded pretty well. Then, with routes as the second, I am not able to load them because the browser tries to locate that files as:</p>
  
  <pre><code>http://myserver/login/public/css/someCSS.css  instead of
  http://myserver/public/css/someCSS.css
  </code></pre>
  
  <p>In this case, I understand why it's adding the <code>login</code> to the URL. <strong>So, my question is, how it's normally handled?</strong></p>
  
  <p>By now I added the domain and folder to the imports, example:</p>
  
  <pre><code>&lt;script src="MyDomain.com/public/js/SomeJS.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>But I really don't want to do it in this way, because anytime that the domain change I should be editing the code and it's not really pratical. Also, I don't want to add the imports of the libraries in every view that I create. I have some files (CSS and JS) that are common for all the project and I just want writte it once.</p>
  
  <p>Thank you!</p>