Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server side rendering #23

Closed
josebalius opened this issue May 13, 2022 · 1 comment
Closed

Server side rendering #23

josebalius opened this issue May 13, 2022 · 1 comment

Comments

@josebalius
Copy link

Watched the demo and it was pretty good!

I am curious if you've thought about adding a way of rendering the views server-side instead of using Svelte? For example, using Go's templating system. I realize you lose out on the component capabilities of today's FE frameworks, but as someone who prefers server-side rendered apps, I think this would be a good feature to support. As mentioned it can be another variation that bud supports in addition to svelte, React and others.

@matthewmueller
Copy link
Contributor

matthewmueller commented May 14, 2022

Hey @josebalius, thanks opening this issue. SSR rendering works out of the box already! The Svelte files will get rendered server-side into HTML, then hydrated on the client-side.

This is similar to what most other JS frameworks do, it works like this:

  1. Create two builds: one for server, one for browser. Both are built using ESBuild. In development, builds happen lazily upon request, similar to how a CDN like esm.sh would build JS to be imported. This will hopefully allow the build system to scale for larger apps. Vite was my inspiration here, but it's all done in Go.

  2. V8 and the Svelte compiler are baked into the bud binary. When a request comes in, V8 evaluates the compiler running the server-built page and returns HTML. That's a mouthful, hopefully that makes sense.

This was hard to do, but I couldn't live with the tradeoff of choosing between: a modern frontend language vs. performance, SEO and the website working without JS.

I should have shown it in the demo, but if you go through the HN demo, try running curl :3000 and you'll be overwhelmed with a beautiful HTML soup!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants