save bytes in client templates

This commit is contained in:
Azareal 2020-03-22 10:25:10 +10:00
parent 5419af9c1c
commit 75ed0cd5f2
5 changed files with 23 additions and 19 deletions

View File

@ -185,13 +185,18 @@ func (list SFileList) JSTmplInit() error {
data = replace(data, " c.", "") data = replace(data, " c.", "")
data = replace(data, "phrases.", "") data = replace(data, "phrases.", "")
data = replace(data, ", 10;", "") data = replace(data, ", 10;", "")
//data = replace(data, "var plist = GetTmplPhrasesBytes("+shortName+"_tmpl_phrase_id)", "const plist = tmplPhrases[\""+tmplName+"\"];") //data = replace(data, "var plist = GetTmplPhrasesBytes("+shortName+"_tmpl_phrase_id)", "const plist = tmplPhrases[\""+tmplName+"\"];")
data = replace(data, "//var plist = GetTmplPhrasesBytes("+shortName+"_tmpl_phrase_id)", "const "+shortName+"_phrase_arr = tmplPhrases[\""+tmplName+"\"];") //data = replace(data, "//var plist = GetTmplPhrasesBytes("+shortName+"_tmpl_phrase_id)", "const "+shortName+"_phrase_arr = tmplPhrases[\""+tmplName+"\"];")
data = replace(data, "var cached_var_", "let cached_var_") data = replace(data, "//var plist = GetTmplPhrasesBytes("+shortName+"_tmpl_phrase_id)", "const pl=tmplPhrases[\""+tmplName+"\"];")
data = replace(data, `tmpl_vars, ok := tmpl_i.`, `/*`) data = replace(data, shortName+"_phrase_arr", "pl")
data = replace(data, "tmpl_"+shortName+"_vars", "t_vars")
data = replace(data, "var c_var_", "let c_var_")
data = replace(data, `t_vars, ok := tmpl_i.`, `/*`)
data = replace(data, "[]byte(", "") data = replace(data, "[]byte(", "")
data = replace(data, "StringToBytes(", "") data = replace(data, "StringToBytes(", "")
data = replace(data, "RelativeTime(tmpl_"+shortName+"_vars.", "tmpl_"+shortName+"_vars.Relative") data = replace(data, "RelativeTime(t_vars.", "t_vars.Relative")
// TODO: Format dates properly on the client side // TODO: Format dates properly on the client side
data = replace(data, ".Format(\"2006-01-02 15:04:05\"", "") data = replace(data, ".Format(\"2006-01-02 15:04:05\"", "")
data = replace(data, ", 10", "") data = replace(data, ", 10", "")
@ -239,7 +244,7 @@ func (list SFileList) JSTmplInit() error {
return err return err
} }
// Don't use Gzip if we get meagre gains from it as it takes longer to process the responses // Don't use Gzip if we get meagre gains from it as it takes longer to process the responses
if len(gzipData) >= (len(data) + 150) { if len(gzipData) >= (len(data) + 120) {
gzipData = nil gzipData = nil
} else { } else {
diff := len(data) - len(gzipData) diff := len(data) - len(gzipData)

View File

@ -1959,7 +1959,7 @@ func (c *CTemplateSet) afterTemplate(con CContext, startIndex int) {
varmap := make(map[string]int) varmap := make(map[string]int)
for name, count := range varcounts { for name, count := range varcounts {
if count > 1 { if count > 1 {
varstr += "var cached_var_" + strconv.Itoa(i) + " = " + name + "\n" varstr += "var c_var_" + strconv.Itoa(i) + "=" + name + "\n"
varmap[name] = i varmap[name] = i
i++ i++
} }
@ -1979,7 +1979,7 @@ func (c *CTemplateSet) afterTemplate(con CContext, startIndex int) {
} else if item.Type == "varsub" && loopDepth == 0 { } else if item.Type == "varsub" && loopDepth == 0 {
index, ok := varmap[item.Body] index, ok := varmap[item.Body]
if ok { if ok {
item.Body = "cached_var_" + strconv.Itoa(index) item.Body = "c_var_" + strconv.Itoa(index)
item.Type = "cvarsub" item.Type = "cvarsub"
outBuf[i] = item outBuf[i] = item
} }

View File

@ -1,6 +1,6 @@
{{template "header.html" . }} {{template "header.html" . }}
<main id="topicsItemList" itemscope itemtype="http://schema.org/ItemList"> <main id="topicsItemList" itemscope itemtype="http://schema.org/ItemList">
<link rel="canonical" href="//{{.Site.URL}}/topics/{{if eq .Sort.SortBy "mostviewed"}}most-viewed/{{end}}{{if gt .Page 1}}?page={{.Page}}{{end}}"/> <link rel="canonical"href="//{{.Site.URL}}/topics/{{if eq .Sort.SortBy "mostviewed"}}most-viewed/{{end}}{{if gt .Page 1}}?page={{.Page}}{{end}}"/>
<div class="rowblock rowhead topic_list_title_block{{if .CurrentUser.Loggedin}} has_opt{{end}}"> <div class="rowblock rowhead topic_list_title_block{{if .CurrentUser.Loggedin}} has_opt{{end}}">
<div class="rowitem topic_list_title"><h1 itemprop="name">{{.Title}}</h1></div> <div class="rowitem topic_list_title"><h1 itemprop="name">{{.Title}}</h1></div>
@ -26,8 +26,7 @@
<a class="moderate_link" href="#" aria-label="{{lang "topic_list.moderate_aria"}}"></a> <a class="moderate_link" href="#" aria-label="{{lang "topic_list.moderate_aria"}}"></a>
</div> </div>
{{else}}<div class="opt locked_opt" title="{{lang "topics_locked_tooltip"}}" aria-label="{{lang "topics_locked_aria"}}"><a></a></div>{{end}} {{else}}<div class="opt locked_opt" title="{{lang "topics_locked_tooltip"}}" aria-label="{{lang "topics_locked_aria"}}"><a></a></div>{{end}}
</div> </div><div style="clear:both;"></div>
<div style="clear:both;"></div>
{{end}} {{end}}
</div> </div>
@ -39,7 +38,7 @@
{{/** TODO: Add ARIA attributes for this **/}} {{/** TODO: Add ARIA attributes for this **/}}
<div id="mod_topic_mover" class="modal_pane auto_hide"> <div id="mod_topic_mover" class="modal_pane auto_hide">
<form action="/topic/move/submit/?s={{.CurrentUser.Session}}" method="post"> <form action="/topic/move/submit/?s={{.CurrentUser.Session}}" method="post">
<input id="mover_fid" name="fid" value=0 type="hidden"/> <input id="mover_fid"name="fid" value=0 type="hidden"/>
<div class="pane_header"> <div class="pane_header">
<h3>{{lang "topic_list.move_head"}}</h3> <h3>{{lang "topic_list.move_head"}}</h3>
</div> </div>
@ -54,7 +53,7 @@
</form> </form>
</div> </div>
<div class="rowblock topic_create_form quick_create_form auto_hide" aria-label="{{lang "quick_topic.aria"}}"> <div class="rowblock topic_create_form quick_create_form auto_hide" aria-label="{{lang "quick_topic.aria"}}">
<form name="topic_create_form_form" id="quick_post_form" enctype="multipart/form-data" action="/topic/create/submit/?s={{.CurrentUser.Session}}" method="post"></form> <form name="topic_create_form_form"id="quick_post_form" enctype="multipart/form-data"action="/topic/create/submit/?s={{.CurrentUser.Session}}" method="post"></form>
<img class="little_row_avatar" src="{{.CurrentUser.MicroAvatar}}" height=64 alt="{{lang "quick_topic.avatar_alt"}}" title="{{lang "quick_topic.avatar_tooltip"}}"/> <img class="little_row_avatar" src="{{.CurrentUser.MicroAvatar}}" height=64 alt="{{lang "quick_topic.avatar_alt"}}" title="{{lang "quick_topic.avatar_tooltip"}}"/>
<div class="main_form"> <div class="main_form">
<div class="topic_meta"> <div class="topic_meta">

View File

@ -1,10 +1,10 @@
<div class="topic_row{{if .Sticky}} topic_sticky{{else if .IsClosed}} topic_closed{{end}}" data-tid="{{.ID}}"> <div class="topic_row{{if .Sticky}} topic_sticky{{else if .IsClosed}} topic_closed{{end}}" data-tid="{{.ID}}">
<div class="rowitem topic_left passive datarow"> <div class="rowitem topic_left passive datarow">
<span class="selector"></span> <span class="selector"></span>
<a href="{{.Creator.Link}}"><img src="{{.Creator.MicroAvatar}}" height=64 alt="Avatar" title="{{.Creator.Name}}'s Avatar" aria-hidden="true"/></a> <a href="{{.Creator.Link}}"><img src="{{.Creator.MicroAvatar}}" height=64 alt="Avatar"title="{{.Creator.Name}}'s Avatar"aria-hidden="true"/></a>
<span class="topic_inner_left"> <span class="topic_inner_left">
<a class="rowtopic" href="{{.Link}}" itemprop="itemListElement" title="{{.Title}}"><span>{{.Title}}</span></a> {{if .ForumName}}<a class="rowsmall parent_forum" href="{{.ForumLink}}" title="{{.ForumName}}">{{.ForumName}}</a>{{end}} <a class="rowtopic"href="{{.Link}}"itemprop="itemListElement" title="{{.Title}}"><span>{{.Title}}</span></a> {{if .ForumName}}<a class="rowsmall parent_forum"href="{{.ForumLink}}"title="{{.ForumName}}">{{.ForumName}}</a>{{end}}
<br><a class="rowsmall starter" href="{{.Creator.Link}}" title="{{.Creator.Name}}">{{.Creator.Name}}</a> <br><a class="rowsmall starter"href="{{.Creator.Link}}"title="{{.Creator.Name}}">{{.Creator.Name}}</a>
{{/** TODO: Avoid the double '|' when both .IsClosed and .Sticky are set to true. We could probably do this with CSS **/}} {{/** TODO: Avoid the double '|' when both .IsClosed and .Sticky are set to true. We could probably do this with CSS **/}}
{{if .IsClosed}}<span class="rowsmall topic_status_e topic_status_closed"title="{{lang "status.closed_tooltip"}}"> | &#x1F512;&#xFE0E</span>{{end}} {{if .IsClosed}}<span class="rowsmall topic_status_e topic_status_closed"title="{{lang "status.closed_tooltip"}}"> | &#x1F512;&#xFE0E</span>{{end}}
{{if .Sticky}}<span class="rowsmall topic_status_e topic_status_sticky"title="{{lang "status.pinned_tooltip"}}"> | &#x1F4CD;&#xFE0E</span>{{end}} {{if .Sticky}}<span class="rowsmall topic_status_e topic_status_sticky"title="{{lang "status.pinned_tooltip"}}"> | &#x1F4CD;&#xFE0E</span>{{end}}
@ -24,7 +24,7 @@
</div> </div>
<div class="rowitem topic_right passive datarow"> <div class="rowitem topic_right passive datarow">
<div class="topic_right_inside"> <div class="topic_right_inside">
<a href="{{.LastUser.Link}}"><img src="{{.LastUser.MicroAvatar}}" height=64 alt="Avatar" title="{{.LastUser.Name}}'s Avatar" aria-hidden="true"/></a> <a href="{{.LastUser.Link}}"><img src="{{.LastUser.MicroAvatar}}" height=64 alt="Avatar"title="{{.LastUser.Name}}'s Avatar" aria-hidden="true"/></a>
<span> <span>
<a href="{{.LastUser.Link}}" class="lastName" title="{{.LastUser.Name}}">{{.LastUser.Name}}</a><br> <a href="{{.LastUser.Link}}" class="lastName" title="{{.LastUser.Name}}">{{.LastUser.Name}}</a><br>
<a href="{{.Link}}?page={{.LastPage}}{{if .LastReplyID}}#post-{{.LastReplyID}}{{end}}" class="rowsmall lastReplyAt" title="{{abstime .LastReplyAt}}">{{reltime .LastReplyAt}}</a> <a href="{{.Link}}?page={{.LastPage}}{{if .LastReplyID}}#post-{{.LastReplyID}}{{end}}" class="rowsmall lastReplyAt" title="{{abstime .LastReplyAt}}">{{reltime .LastReplyAt}}</a>

View File

@ -1,9 +1,9 @@
<div class="topic_row{{if .Sticky}} topic_sticky{{else if .IsClosed}} topic_closed{{end}}" data-tid={{.ID}}> <div class="topic_row{{if .Sticky}} topic_sticky{{else if .IsClosed}} topic_closed{{end}}"data-tid={{.ID}}>
<div class="rowitem topic_left passive datarow"> <div class="rowitem topic_left passive datarow">
<a href="{{.Creator.Link}}"><img src="{{.Creator.MicroAvatar}}" height=64 alt="Avatar"title="{{.Creator.Name}}'s Avatar"aria-hidden="true"/></a> <a href="{{.Creator.Link}}"><img src="{{.Creator.MicroAvatar}}" height=64 alt="Avatar"title="{{.Creator.Name}}'s Avatar"aria-hidden="true"/></a>
<span class="topic_inner_left"> <span class="topic_inner_left">
<span class="rowtopic" itemprop="itemListElement"title="{{.Title}}"><a href="{{.Link}}">{{.Title}}</a>{{if .ForumName}}<a class="parent_forum_sep">-</a><a href="{{.ForumLink}}" title="{{.ForumName}}" class="rowsmall parent_forum">{{.ForumName}}</a>{{end}}</span> <span class="rowtopic"itemprop="itemListElement"title="{{.Title}}"><a href="{{.Link}}">{{.Title}}</a>{{if .ForumName}}<a class="parent_forum_sep">-</a><a href="{{.ForumLink}}" title="{{.ForumName}}" class="rowsmall parent_forum">{{.ForumName}}</a>{{end}}</span>
<br><a class="rowsmall starter" href="{{.Creator.Link}}" title="{{.Creator.Name}}">{{.Creator.Name}}</a> <br><a class="rowsmall starter"href="{{.Creator.Link}}"title="{{.Creator.Name}}">{{.Creator.Name}}</a>
</span> </span>
</div> </div>
<div class="topic_middle"> <div class="topic_middle">