Go Template rendering or alternative

Let discuss on template libraries, using {{range}} in multiple loop will slow down with HTML escaping and rendering to the template. Is there a better approach to escape Posts in one pass before rendering with html/template?

Forum.go


import("html/template")

var tmpl = template.Must(template.ParseFiles("index.html"))

type Thread struct {
	Title   string
}

type ListThreads struct {
    Threads []*Thread
}

Posts := make([]*Thread, 30)
p := ListThreads{Posts}
tmpl.Execute(w, &p)

Template.html

{{ range .Threads }}
{{ .Title }}
{{ end }}

I also considerig Jet Template for fast on the fly rendering for speed improvement is worth a try?

I found that CSR (client side rendering) often is faster than SSR (server side rendering). So I have decided use AJAX instead of Go for that reason. If you are creating a list with Go templates using {{range}} the page will not render completely until last record is loaded. Here is my attempt with AJAX (CSR) and 3000 records. https://form.go4webdev.org/aggrid here is the same using Go (SSR): https://goapi.go4webdev.org/ques It is not big different in speed, but the SSR render some parts with a delay.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.