SSX: Pre-rendered Sites
@inglorious/ssx renders Inglorious Web apps to HTML on the server, then hydrates them in the browser. It has docs of its own; this page is how it fits with what you know from Inglorious Web.
The same types, rendered on the server
A page is a file in src/pages/ that exports an Inglorious Web type, and its entity is filled by its load on the server:
javascript
// src/pages/posts/_id.js
import { html } from "@inglorious/web"
export const ssr = true
export async function load(entity, page) {
entity.post = await getPost(page.params.id)
}
export const Post = {
render(entity) {
return html`<article>
<h1>${entity.post.title}</h1>
<div>${entity.post.body}</div>
</article>`
},
}The HTML arrives rendered; when the JavaScript loads, the page becomes the same store-driven app as any other, with client-side navigation between pages.
Static or rendered on request
- Static, the default:
ssx buildrenders each page once todist/, for any static host. A dynamic route lists its paths withstaticPaths. - On request: a page that exports
ssris rendered for each request, with itsloadgiven the URL'sparamsand therequest, to read headers and cookies from.ssx ssrserves such a site.
Both can live in one site, beside API routes in src/api/.
Get started
bash
pnpm create @inglorious/app my-site --template=ssx-js
cd my-site
pnpm devAdd --syntax=jsx or --syntax=vue to write the pages in JSX or Vue-like templates.
Next: the SSX guide, and its rendering modes.
