rubyjs / mini_racer

Minimal embedded v8
MIT License
585 stars 91 forks source link

Suggestions for context defaults for server side rendering #297

Closed jho406 closed 5 months ago

jho406 commented 6 months ago

Hi! I recently built Humid, a very light wrapper around mini_racer to make server side rendering easier to setup for JS projects with Rails/Puma. I was wondering if ya'll would be able to recommend some defaults for options passed to MiniRacer::Context.new. Right now, i have that set as empty, but am recommending

timeout: 1000,
ensure_gc_after_idle: 2000

in my README. I'm also open to any suggestions or feedback on the project if any.

Thanks for the wonderful library!

SamSaffron commented 6 months ago

yes, both of those are good ideas for a serve side renderer.

tisba commented 6 months ago

Depending if you're using a forking web server, you also need to be careful around forking, see https://github.com/rubyjs/mini_racer#fork-safety.

jho406 commented 6 months ago

Thanks @tisba! Agreed. I'm assuming most projects would be using Puma which forks in clustered mode. I had taken those instructions and added an example on how to work with puma.

# Puma
on_worker_boot do
  Humid.create_context # Calls MiniRacer::Context.new
end

on_worker_shutdown do
  Humid.dispose # disposes of the mini_racer context via `dispose`
end

Does that feel like a good enough start?

jho406 commented 5 months ago

Thanks everyone for all the suggestions. I'll close this Issue and make changes over at Humid.