Browse Source

http2/h2demo: show load times on gophertimes demo page

Change-Id: I3d3905adab74a83c9d7d72c829f6686b514f3aaf
Reviewed-on: https://go-review.googlesource.com/15060
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Arnout Engelen 10 years ago
parent
commit
c2528b2dd8
1 changed files with 11 additions and 2 deletions
  1. 11 2
      http2/h2demo/h2demo.go

+ 11 - 2
http2/h2demo/h2demo.go

@@ -287,7 +287,7 @@ func newGopherTilesHandler() http.Handler {
 				return
 			}
 		}
-		io.WriteString(w, "<html><body>")
+		io.WriteString(w, "<html><body onload='showtimes()'>")
 		fmt.Fprintf(w, "A grid of %d tiled images is below. Compare:<p>", xt*yt)
 		for _, ms := range []int{0, 30, 200, 1000} {
 			d := time.Duration(ms) * nanosPerMilli
@@ -305,7 +305,16 @@ func newGopherTilesHandler() http.Handler {
 			}
 			io.WriteString(w, "<br/>\n")
 		}
-		io.WriteString(w, "<hr><a href='/'>&lt;&lt Back to Go HTTP/2 demo server</a></body></html>")
+		io.WriteString(w, `<p><div id='loadtimes'></div></p>
+<script>
+function showtimes() {
+	var times = 'Times from connection start:<br>'
+	times += 'DOM loaded: ' + (window.performance.timing.domContentLoadedEventEnd - window.performance.timing.connectStart) + 'ms<br>'
+	times += 'DOM complete (images loaded): ' + (window.performance.timing.domComplete - window.performance.timing.connectStart) + 'ms<br>'
+	document.getElementById('loadtimes').innerHTML = times
+}
+</script>
+<hr><a href='/'>&lt;&lt Back to Go HTTP/2 demo server</a></body></html>`)
 	})
 }