Live reload not working - reload script not injected
Live Reload refresh isn't working in the browser, the go app rebuilds on any changes but the browser isn't reloading.
With GoFiber I am creating a server like
log.Fatal(app.Listen(":3000"))
Rendering the page on route /
app.Get("/", func(c *fiber.Ctx) error {
return c.Render("page/index", &fiber.Map{}, "layout/layout-default")
})
but when I change anything in "page/index" I have to manually refresh. Checking the source code in the browser via "View Source" shows no injected script for live reload. The layout-default I am rendering the page with contains a <body> element.
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format
# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "."
tmp_dir = "tmp"
[build]
cmd = "task build"
bin = "main"
full_bin = ""
include_ext = ["go", "tpl", "tmpl", "html"]
exclude_dir = ["tmp"]
include_dir = ["src"]
exclude_file = []
exclude_unchanged = false
follow_symlink = false
log = "air.log"
delay = 1000
stop_on_error = true
send_interrupt = true
# Delay after sending Interrupt signal
kill_delay = 0 # ms
poll = false
poll_interval = 500
[log]
time = true
silent = false
[color]
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"
[misc]
clean_on_exit = true
[screen]
clear_on_rebuild = true
keep_scroll = true
[proxy]
enabled = true
proxy_port = 3001
app_port = 3000
It works if I add the script manually to my layout-default, but I think it should be injected automatically for all pages?
<script>new EventSource("http://localhost:3001/internal/reload").onmessage = () => { location.reload() }</script>
What is the Content-Type header in your handler's response? The proxy only tries to inject the script in responses that are advertised as text/html.
I verified that the Content-Type header contains text/html and that a body tag exists. Yet, the script is not injected
I did some debugging and discovered that air does not decode the body with gzip or brotli. So if your go server behind the proxy encodes the body, the proxy is unable to find the body tag.
This is a late reply, but maybe GoFiber encodes the body for you @pczern. You can try disabling the encoding when using air until the air proxy is not fixed
#661 mentions gzip breaking the proxy
@devgioele that's probably it, I am using gofiber's LevelBestSpeed compress middleware.
app.Use(compress.New(compress.Config{
Level: compress.LevelBestSpeed,
}))