title: Should I call template.ParseFiles(...) on each http request or only once from the main function?
body: <p>I am doing some web develoment using the go programming language using the package <code>html/template</code>. At some point of the code, I need to call the function <code>template.ParseFiles(...)</code> so I can create a template from those files ad then execute it using <code>temp.Execute(w,data)</code>. I would like to know if it is better to create the template on each request or to do it once in the main and declare a global variable.</p>
  
  <p>Right now I do it on each request on my handle functions, like most tutorials do. However, I don't know If I'm wasting resources by doing it on each request instead of having them as global variables.</p>
  
  <p>This is how it looks on each request</p>
  
  <pre class="lang-golang prettyprint-override"><code>func ViewStats(w http.ResponseWriter, r *http.Request) {
      //Get stuff from db and put them in data
      //...
      //return data to user
      tmp, err := template.ParseFiles("views/guest-layout.html",
          "views/stats.html")
  
      if err != nil {
          fmt.Println(err)
      } else {
          tmp.Execute(w,data)
      }
  }
  </code></pre>
  
  <p>I would like to know if this is better:</p>
  
  <pre class="lang-golang prettyprint-override"><code>var temp1 template.Template
  
  func main() {
      temp1, err = template.ParseFiles("file1","file2") 
      //...
  }
  </code></pre>