From df489b4712dd59b097de0d2fb84cfac7a013f5cd Mon Sep 17 00:00:00 2001 From: bep Date: Wed, 10 Sep 2014 12:21:22 +0200 Subject: Enable soft livereload of CSS and images Prior to this commit a dummy JavaScript filename was sent to LiveReload when changing a static file (CSS, image etc.), forcing a full browser reload of the page. This commit fixes this by sending the relative file path of the changed static resource, enabling partial live reloading for CSS- and image-changes. If more than one static file happens to end up in the same changeevent-batch, it will fall back to do a full refresh. To enable this logic, the change events with names ending with ".goutputstream*" is now filtered out as temporary. Changes in dynamic content behaves like before. Issue #490 --- livereload/livereload.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'livereload') diff --git a/livereload/livereload.go b/livereload/livereload.go index 9fb24696d..29a6168a5 100644 --- a/livereload/livereload.go +++ b/livereload/livereload.go @@ -39,7 +39,12 @@ func Initialize() { func ForceRefresh() { // Tell livereload a js file changed to force a hard refresh - wsHub.broadcast <- []byte(`{"command":"reload","path":"/x.js","originalPath":"","liveCSS":true}`) + RefreshPath("/x.js") +} + +func RefreshPath(s string) { + // Tell livereload a file has changed - will force a hard refresh if not CSS or an image + wsHub.broadcast <- []byte(`{"command":"reload","path":"` + s + "\"" + `,"originalPath":"","liveCSS":true,"liveImg":true}`) } func ServeJS(w http.ResponseWriter, r *http.Request) { -- cgit v1.2.3