transform/livereloadinject: Add defer to livereload script tag
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 31 Jan 2020 07:15:22 +0000 (08:15 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 31 Jan 2020 07:15:22 +0000 (08:15 +0100)
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.

transform/livereloadinject/livereloadinject.go
transform/livereloadinject/livereloadinject_test.go

index 896dcab4e371f4bb8acf21f5d22d53c06ab94a29..bbafdff72e77bf6d70ef4a84cfb4eb25674f2576 100644 (file)
@@ -59,7 +59,7 @@ func New(port int) transform.Transformer {
                        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 {
index ea1b3aa653e7008966b55cdd176611588e3363c8..690db31c2347bbe9a5d30675bb0e05a399f71641 100644 (file)
@@ -25,7 +25,7 @@ import (
 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)