Answer the question
In order to leave comments, you need to log in
Is template parsing happening at compile time or at runtime of the GO code?
Please do not kick much, I just like to know how it works inside and how to optimize and speed it up.
Explain how template parsing works internally.
Which option is better in terms of performance and resources.
Option 1 - Global variable
var t, err = template.ParseFiles("templates/wt/index.html", "templates/wt/header.html", "templates/wt/footer.html")
func main(){
}
func indexHandler(w, r){
t.ExecuteTemplate(w, "index", locale)
}
func main(){
t, err := template.ParseFiles("templates/wt/index.html", "templates/wt/header.html", "templates/wt/footer.html")
}
func indexHandler(w, r, t){
t.ExecuteTemplate(w, "index", locale)
}
func main(){
}
func indexHandler(w, r){
t, err := template.ParseFiles("templates/wt/index.html", "templates/wt/header.html", "templates/wt/footer.html")
t.ExecuteTemplate(w, "index", locale)
}
Answer the question
In order to leave comments, you need to log in
In the first option, how will you handle errors?
In the third option, for each request, files with templates will be opened and parsed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question