Introducing Photon
⛔This is a work-in-progress draft.
We (Joël and Rom) are thrilled to introduce Photon — a next-generation infrastructure for deploying JavaScript servers anywhere (self-hosting, Cloudflare, Vercel, Netlify, ...) with support for popular server frameworks (Hono, Express.js, Fastify, ...).
It leverages Vite's Environment API — a novel approach enabling first-class integration with deployment providers, delivering unprecedented DX. See Features.
We believe Photon represents the future of JavaScript deployment, see Why Photon?
If you use
vike-server
you can easily migrate to Photon. See Migration tovike-photon
.
Features
Any server framework
Photon supports all popular server frameworks: Hono, Express.js, Elysia, Fastify, H3, Srvx, and Hattip.
This means you can create a server using your favorite framework and deploy it anywhere.
Server HMR
If you change a server file, the server code is automatically updated: the next HTTP response will be generated by the latest code. No more full server reload required.
This is experimental and doesn't always work:
vike-server
sometimes still triggers a full server reload.
If HMR isn't what you want (for example if you modify the database connection) you can manually trigger a full server reload by pressing r + enter
.
Server-side code splitting
To reduce cold starts, Photon supports server-side code splitting: each page get's its own separate production bundle — each bundle is minimal and contains only what is needed to render that page.
This means you can scale to hundreds of pages while keeping you server cold starts low.
Cloudflare Workers development DX
Cloudflare recently introduced @cloudflare/vite-plugin
, which runs the server-side of the user's app inside workerd
— the same runtime Cloudflare Workers use in production.
This means the development environment is now a faithful representation of Cloudflare's production edge environment (miniflare was only mimicking it).
With Miniflare, there are many discrepancies between dev and prod, which lead to less DRY, poord DX, complicated architecture (it was notoriously unclear what the integrating with Cloudflare notoriously). These issue are now all gone — if your works in dev, you now can have much more confidence it also works in production.
Vike is the second framework (after React Router) that supports this. Shout out to the Cloudflare and Vite Team — in particular James Opstad, @sapphi-red, and Hiroshi Ogawa — who helped us integrate Vike, Photon,
@cloudflare/vite-plugin
, and Vite's Environment API.
It's all powered by Vite's Environment API. It enables Vite to run in a Node.js process while running he user code in another non-Node.js process such as
workerd
. The design and API was developed with massive collaboration between the Vite Team, Cloudflare, and framework authors. Shows that collaboration...
Vercel
The @photonjs/vercel
package includes all the vite-plugin-vercel
features, most notably ISR.
It now also supports deploying to Vercel edge.
- TODO: actually Vercel edge is deprecated? See https://x.com/leerob/status/1780705942734331983
Netlify
First-class support for Netlify is work-in-progress.
Self-host
You don't have to use any of the aforementioned deployment providers — you can self-host your server instead, for example on AWS or a VPS.
Why Photon?
Vite has become a common infrastructure shared across many frameworks, and we believe the same will happen for JavaScript deployment.
Agnostic
While developing vike-server
we realized most code is agnostic to Vike. So we decided to make Vike's deployment infrastructure fully agnostic.
That's what Photon is: it's everything we learned while developing vike-server
, vike-cloudflare
, and vite-plugin-vercel
bundled in one cohesive tool with improved DX and new features — all that completely agnostic to Vike.
Any Vite-based framework can integrate Photon and offer all Photon's features to their users.
Collaboration
We believe collaborative infrastructure will eventually outpace non-collaborative ones. For example, the incredible collaboration around Vite has made it very challenging for others to keep up.
We invite and vividly encourage Vite-based frameworks to collaborate on deployment.
Nitro
So far, Nitro has limited success spreading outside of Nuxt, because it isn't flexible enough. Nitro enforces opinions and architectural decisions that it shouldn't. We believe Nitro must (and eventually will) follow Photon's footsepts and become more do-one-thing-do-it-well.
For users, the best oucome is having the choice between Nitro and Photon — with a vibrant and constructive competition between the two.