title: How do I serve CSS and JS in Go
body: <p>I followed the <a href="https://golang.org/doc/articles/wiki/" rel="noreferrer">Go Writing Web Applications</a> tutorial but for whatever reason I am having trouble getting the app to serve CSS and JS. If I run my static page without the Go server the page CSS works fine. When I run the Go server on the other hand the CSS just doesn't work.</p>
  <p>Here is what my HTML sort of looks like:</p>
  <pre><code>&lt;link rel=&quot;stylesheet&quot; href=&quot;../assets/css/bootstrap.min.css&quot;&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;../assets/css/bootstrap-theme.min.css&quot;&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;../assets/css/custom.css&quot;&gt;
          
  </code></pre>
  <p>then under the <code>body</code> tag:</p>
  <pre><code>&lt;script src=&quot;../assets/js/jquery.min.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;../assets/js/bootstrap.min.js&quot;&gt;&lt;/script&gt;
  </code></pre>
  <p>My file tree looks like this:</p>
  <pre><code>go-affect/
  ├── data
  │   └── …
  ├── static
  │   ├── css
  │   │   └── …
  │   └── js
  │   │   └── …
  ├── tmpl
  │   ├── edit.html
  │   ├── index.html
  │   └── view.html
  └── main.go
  </code></pre>
  <p>How do I get my Go application to serve the CSS and JavaScript I need?</p>
  <p><strong>EDIT:</strong></p>
  <p>The problem has since been solved, here is the working main:</p>
  <pre><code>func main() {
      http.HandleFunc(&quot;/view/&quot;, makeHandler(viewHandler))
      http.HandleFunc(&quot;/edit/&quot;, makeHandler(editHandler))
      http.HandleFunc(&quot;/save/&quot;, makeHandler(saveHandler))
      http.HandleFunc(&quot;/index/&quot;, makeHandler(indexHandler))
  
      
      http.Handle(&quot;/static/&quot;, http.StripPrefix(&quot;/static/&quot;, http.FileServer(http.Dir(&quot;static&quot;))))
  
      http.ListenAndServe(&quot;:8080&quot;, nil)
  }
  </code></pre>
  <p>Here is an example of the handlers I am using:</p>
  <pre><code>func indexHandler(w http.ResponseWriter, r *http.Request, title string) {
      p := &amp;Page{Title: title}
      err := templates.ExecuteTemplate(w, &quot;index.html&quot;, p)
      if err != nil {
          http.Error(w, err.Error(), http.StatusInternalServerError)
      }
  }
  </code></pre>