thanos

thanos

Hi Elixir Drinkers!

I just published PhoenixPrerender, a library that brings static site generation and incremental static regeneration (ISR) to Phoenix — think Next.js ISR or SvelteKit prerendering, but built entirely on the BEAM.

I hope it’s of use. I been using it in production on several sites I thought I package it let it out into the big bad world.

The problem

Phoenix is great at rendering HTML, but for pages that rarely change (marketing pages, docs, changelogs), you’re paying the full rendering cost on every request — router matching, controller dispatch, template compilation, layout assembly. That adds up at scale.

What PhoenixPrerender does

  1. Build time: mix phoenix.prerender renders your marked routes through the full Phoenix endpoint pipeline and writes static HTML files to disk
  2. Runtime: A plug intercepts requests and serves those files directly — ~200μs instead of ~22ms (110x faster)
  3. ISR: When pages go stale, the next request serves the existing content immediately while triggering a background regeneration. Users never wait.

Setup takes 5 minutes

# 1. Add the dep
{:phoenix_prerender, "~> 0.1.0"}

# 2. Mark routes
import PhoenixPrerender

prerender do
  get "/about", PageController, :about
  get "/pricing", PageController, :pricing
  live "/docs", DocsLive
end

# 3. Add the plug (before the router)
plug PhoenixPrerender.Plug

# 4. Configure
config :phoenix_prerender, enabled: true

# 5. Generate
# $ mix phoenix.prerender

That’s it. Everything else is opt-in.

Key features

  • Router macro — prerender do ... end wraps routes cleanly, or use metadata: %{prerender: true} explicitly
  • Three-tier serving — ETS memory cache → disk → Phoenix fallback
  • ISR — stale-while-revalidate with configurable TTL, ETS-based locks prevent thundering herd
  • Distributed — cluster-wide locking via :global.trans/2, cache invalidation via Phoenix PubSub
  • LiveView compatible — prerender LiveView routes; the static HTML includes data-phx-session attributes so the browser hydrates normally
  • Atomic writes — write to .tmp then rename, so you never serve a partial file
  • Concurrent generation — parallel rendering with Task.async_stream
  • Manifest + sitemap — automatic manifest.json (with checksums) and sitemap.xml
  • Telemetry — events for generation, rendering, serving, and regeneration
  • Strict paths — only serve paths listed in the manifest (enabled by default)

Benchmarks

Same /about page (10.6 KB), Apple M1 Max:

Serving Mode Throughput Latency Memory
Prerendered (ETS cache) 5,000 req/s 200 μs 5.4 KB
Prerendered (disk) 4,040 req/s 248 μs 8.3 KB
Dynamic (full Phoenix) 45 req/s 22,134 μs 46.0 KB

110x faster, 8.5x less memory per request.

What this is NOT

  • Not a static site generator that replaces Phoenix — your app still runs normally
  • Not a CDN — but pairs well with one (the Cache-Control header is configurable)
  • Not needed for every page — contact forms, dashboards, personalized content should stay dynamic

Demo app

The repo includes a full demo app that showcases all four rendering modes side by side: prerendered controller pages, LiveView + prerender, ISR, and dynamic. You can run it locally with:

cd demo && mix deps.get && mix phx.server

Links

Feedback, issues, and PRs welcome. Would love to hear if this is useful for your projects.

https://github.com/thanos/phoenix_prerender

Showing Posts 1 to 3

greven

greven

This looks fantastic!
I’m going to try it out on my personal website (https://nuno.site) and will report back!

greven

greven

Reporting back.
Added it to my site as I said I would above.
Works wonders! Pages loaded fast but now they are lightning fast. :smiley:

Good job man, really nice library. This is such a good idea I could it see it being part of Phoenix itself.
I will report any problems I find.

Now I to add the mix command to prerender pages to before I release to keep them updated. :slight_smile:

PS - My server is the smalleste instance of a Hetzner VPS, so 2 vCPU / 4GB RAM.

thanos

thanos OP

I’m using it on the landing page of a big bank. The use case should flush out lots of issues for the next release!

— All posts loaded —

Where Next? Top

Trending in Announcing Top

type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
kip
I’ll shortly be launching Text, a nascent text analysis library. Current functionality In this early version (not ready for prime time) ...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews