htmgo icon indicating copy to clipboard operation
htmgo copied to clipboard

Live reloading the html components should not have to restart the whole server

Open maddalax opened this issue 1 year ago • 11 comments

Since go is compiled, whenever you want to change html/css, the entire server needs to be recompiled and restarted. This is generally fine for small projects, but as projects get larger and more things get loaded on startup, the live reload speed gets slower.

Look into alternatives to make this better, potentially https://github.com/traefik/yaegi to interpret the code on demand

maddalax avatar Oct 27 '24 14:10 maddalax

after a bit of research on yaegi, I'm not sure if it will work.

  1. it doesn't support go modules

  2. seems to be more suited towards smaller scripts with minimal dependencies, whereas using this for htmgo would be difficult because any page would be importing a universe of stuff from htmgo/framework

  3. it doesn't seem to support generics fully, it can't infer the type

func print[T any](v ...[]T) {
        fmt.Println(v)
}
print(values) // Works with: print[string](values), but not print(values)

WASM doesn't seem like a bad idea overall but I think the issue is we do not control the dependencies that their app may use, and their pages may share memory with the host process, such as global variables.

I'm thinking this might not be a worth pursuing at the moment because go's compilation speed is already very fast. It might be more beneficial to work on improving startup times instead

maddalax avatar Oct 28 '24 14:10 maddalax

hey all .

I would like to highlight an approach I have used to server golang as WASM.

I run golang pages on Cloudflare.

https://github.com/syumai/workers shows how to do it , and has great examples .

so all that we would be doing in htmgo is running each page as WASM using wazero instead of Cloudflare .

this will mean each page is its own WASM so that we can keep compile time fast no matter how big the project.

My main worry is still

WASM doesn't seem like a bad idea overall but I think the issue is we do not control the dependencies that their app may use, and their pages may share memory with the host process, such as global variables.

and we likely can't just serve the entire app through WASM, as their app likely has dependencies that aren't supported on wasm.

maddalax avatar Nov 04 '24 12:11 maddalax

https://github.com/janpfeifer/gonb

they figured it out. if a jupyter notebook can do it...

nicosql avatar Jan 03 '25 20:01 nicosql

https://github.com/janpfeifer/gonb

they figured it out. if a jupyter notebook can do it...

What did they figure out? From what I can tell from their README, its compiling the go code and running it as normal, relying on the fact that go compilation is extremely fast

maddalax avatar Jan 03 '25 20:01 maddalax