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

Deployment #352

Closed
pjebs opened this issue Jan 5, 2025 · 13 comments
Closed

Deployment #352

pjebs opened this issue Jan 5, 2025 · 13 comments

Comments

@pjebs
Copy link

pjebs commented Jan 5, 2025

Is a Go server needed for running this on the server?

It says "Go backend" but also says Static Site generator so I got confused.

@jimafisk
Copy link
Member

jimafisk commented Jan 5, 2025

No you do not need Go installed to use Plenti locally or to serve compiled assets for a live site. Go would only be needed if you wanted to contribute to building out the framework itself, sorry for the confusion! You're right that it's a static site generator (SSG).

@pjebs pjebs closed this as completed Jan 5, 2025
@pjebs
Copy link
Author

pjebs commented Jan 5, 2025

@jimafisk Do you now how to do Svelte SSR with Goja (Go JS engine)?

@jimafisk
Copy link
Member

jimafisk commented Jan 5, 2025

I've certainly thought about using Goja (#169), but currently it comes with some pretty significant performance costs over using V8: #3 (comment) (although it's getting better #3 (comment))

The V8 set up has issues as well: slow builds for the Go binary, missing cross compilation targets, memory issues for compiled assets at scale, Svelte upgrade limitations, etc. I'm actually working on some ideas for building a templating engine that would allow SSR and some DOM interactivity using attributes (AlpineJS or something similar). I've been using Goja to evaluate JS and it's working pretty well so far. It's really just ideas at this point https://github.com/jimafisk/custom_go_template

@pjebs
Copy link
Author

pjebs commented Jan 6, 2025

@jimafisk Oh wow. You've done serious investigations into the topic. If you and Matt couldn't solve it, I probably won't be able to do any better given you guys know this space better than me.

In terms of your cgo cross-compilation issue:

  1. https://github.com/ebitengine/purego (you might be able to remove your Go v8 wrapper)
  2. https://dev.to/kristoff/zig-makes-go-cross-compilation-just-work-29ho

@pjebs
Copy link
Author

pjebs commented Jan 6, 2025

I'm working on a Go/Svelte entire framework to "replace" SvelteKit (but still use SvelteKit lol).
Right now it works well and you can deploy Svelte sites with a Go backend. But there is no SSR. That is what I'm trying to solve. (Even if I only perform SSR when the request is made by a search engine crawler)

If you manage to even get a barebone solution with Goja, let me know. That would be awesome. Thanks

@pjebs
Copy link
Author

pjebs commented Jan 6, 2025

https://github.com/K-Sato1995/go-ssr-poc This project uses React + v8

@jimafisk
Copy link
Member

jimafisk commented Jan 6, 2025

If you and Matt couldn't solve it, I probably won't be able to do any better given you guys know this space better than me.

I'm not sure either of us have had time to fully explore it. I don't think it's an easy problem to solve, but new eyes taking a look certainly can't hurt!

I'm working on a Go/Svelte entire framework to "replace" SvelteKit (but still use SvelteKit lol).

That sounds cool! Do you have a link for interested folks who come across this issue in the future?

Right now it works well and you can deploy Svelte sites with a Go backend. But there is no SSR.

Yeah SSR can be tricky. How are you doing the DOM compilation currently? We do both the DOM and SSR targets in V8.

https://github.com/K-Sato1995/go-ssr-poc This project uses React + v8

We use rogchap.com/v8go too, last I checked Matt does as well. The Svelte compiler is a huge chunk of JS code, if you're planning on running it as is, that's probably still your best bet.

@pjebs
Copy link
Author

pjebs commented Jan 6, 2025

I will release what I've done soon and let you know. I'm not compiling the DOM at the moment. That's what I'm exploring. I'm literally just serving the index.html and the js file that svelte compiler has already built and everything is client side.

I'm happy with that. The SSR is a bonus - even if it's just for crawlers. Google states that they don't index client-side websites anywhere near as frequently as a punishment.

@pjebs
Copy link
Author

pjebs commented Jan 6, 2025

This might be useful: https://jtarchie.com/posts/2024-08-30-exploring-goja-a-golang-javascript-runtime

@pjebs
Copy link
Author

pjebs commented Jan 6, 2025

I'm trying something that you might find interesting: sveltejs/svelte#14909 and sveltejs/kit#11836 https://github.com/jsdom/jsdom

@jimafisk
Copy link
Member

jimafisk commented Jan 6, 2025

@pjebs
Copy link
Author

pjebs commented Jan 7, 2025

Here is the solution we are looking for: nichady/golte#16

@pjebs
Copy link
Author

pjebs commented Jan 7, 2025

@jimafisk I don't understand nichady's solution as yet but he has gotten it to work with Svelte and Goja/Goja-Node.

But here is another solution (for React) that is possibly similar to what you are already doing but it appears more cleaner and easier to follow.
It seems to be easily switchable to goja and Svelte.

See:

  1. https://github.com/K-Sato1995/go-ssr-poc/blob/main/main.go#L47 (See buildBackend() and https://github.com/K-Sato1995/go-ssr-poc/blob/main/main.go#L88)
  2. https://github.com/K-Sato1995/go-ssr-poc/blob/main/frontend/serverEntry.jsx (subject to Feature Request: Svelte equivalent to React's renderToString() sveltejs/svelte#14926 I submitted)

The Svelte Team just responded with a solution: sveltejs/svelte#14928

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