Tag: 去模板

使用“模板”包在golang中为客户端生成dynamic网页需要花费太多时间

使用template包为客户端生成一个dynamic网页时,速度非常慢。 testing代码如下,golang 1.4.1 http.Handle("/js/", (http.FileServer(http.Dir(webpath)))) http.Handle("/css/", (http.FileServer(http.Dir(webpath)))) http.Handle("/img/", (http.FileServer(http.Dir(webpath)))) http.HandleFunc("/test", TestHandler) func TestHandler(w http.ResponseWriter, r *http.Request) { Log.Info("Entering TestHandler …") r.ParseForm() filename := NiConfig.webpath + "/test.html" t, err := template.ParseFiles(filename) if err != nil { Log.Error("template.ParseFiles err = %v", err) } t.Execute(w, nil) } 根据日志,我发现t.Execute(w, nil)花了大约3秒钟,我不知道为什么它使用这么多的时间。 我也尝试过Apache服务器来testingtest.html ,它的响应速度非常快。