shithub: hugo

Download patch

ref: b3f0674b80a32425aeb4412f318c720391bbf773
parent: ef78a0d18a13098bcea1ff2b2d45d7388b8d41a0
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Fri Jan 31 03:15:22 EST 2020

transform/livereloadinject: Add defer to livereload script tag

In #6821 we moved the loading from end of body to head to make Turbolinks and similar work.

This commit adds a defer attribute to avoid page parse blocking.

--- a/transform/livereloadinject/livereloadinject.go
+++ b/transform/livereloadinject/livereloadinject.go
@@ -59,7 +59,7 @@
 			return err
 		}
 
-		script := []byte(fmt.Sprintf(`<script src="/livereload.js?port=%d&mindelay=10&v=2" data-no-instant></script>`, port))
+		script := []byte(fmt.Sprintf(`<script src="/livereload.js?port=%d&mindelay=10&v=2" data-no-instant defer></script>`, port))
 
 		i := idx
 		if match.appendScript {
--- a/transform/livereloadinject/livereloadinject_test.go
+++ b/transform/livereloadinject/livereloadinject_test.go
@@ -25,7 +25,7 @@
 func TestLiveReloadInject(t *testing.T) {
 	c := qt.New(t)
 
-	expectBase := `<script src="/livereload.js?port=1313&mindelay=10&v=2" data-no-instant></script>`
+	expectBase := `<script src="/livereload.js?port=1313&mindelay=10&v=2" data-no-instant defer></script>`
 	apply := func(s string) string {
 		out := new(bytes.Buffer)
 		in := strings.NewReader(s)