question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Static Site Generation (SSG) / Pre-rendering

See original GitHub issue

Is your feature request related to a problem?

no

Describe the solution you’d like

There should be a command, maybe something like vite build --mode ssg to generate the application or website pages as prerendered, resumable html files alongside the client js files.

Describe alternatives you’ve considered

Additional context

So far I came up with this basic working solution (for a single page), although I am sure it does not work for all options/settings:

// /build-ssg.mjs
const fs = await import('node:fs/promises'); // currently only works with node.js
const server = await import("./server/entry.ssr.js");

const routes = [{url: "/", outFile: 'dist/index.html'}]; // should be derived from router or provided by developer

for (const route of routes) {
  const { html } = await server.render({ url: route.url });
  await fs.writeFile(route.outFile, html);
}

It relies on the client- and sever-build being generated. It would be smoother if in the end the server part was not necessary to be under server/entry.ssr.js, I think most users would not want SSR and SSG eventually.

Maybe something like this can be integrated into qwik directly. @manucorporat any opinions?

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:6
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

9reactions
manucorporatcommented, Sep 6, 2022

Implemented already!

3reactions
wthocommented, Jul 3, 2022

@nnelgxorz I agree, this is state-of-the-art pre-rendering! 11ty’s Serverless plugin supports three render modes:

  1. Rendering at build time and serving these pre-rendered html files (pre-rendered)
  2. Rendering on-demand at first request and serving these pre-rendered html files, if already rendered (on-demand)
  3. Rendering dynamically, on each request, aka SSR (dynamically)

We basically have to build the SSR server and client bundles at build time via the optimizer/qwikVite. Then we can invoke it during the build to generate html pages at build time. For this we need some smart analysis of all available (static or dynamic) routes from the router or a list of routes the developer wants to pre-render.

At runtime, the server has to handle each request accordingly. The current SSR server only renders each page on each request and serves that html. There we would have to add some logic to:

  • check if the route is pre-rendered/on-demand/dynamically by calling routeRenderMode(...)
  • look for pre-rendered files and load it (pre-rendered / on-demand)
  • render page (on-demand / dynamically)
  • write file to fs (on-demand)
  • serve html (all)

Other features a SSG/Prerender plugin could have:

  • QwikCity router compatibility
  • Configuration which pages are what mode - e. g. a routeRenderMode implemented in src/entry.ssg.tsx
    • Optimally this function call also already includes QwikCity routing information for the current route
    • Possible signature: function routeRenderMode(url: string, routes: QwikCityRouterData): 'pre-rendered' | 'on-demand' | 'dynamic'
  • CLI command to output bundles, assets and pre-rendered html files in output folder, e. g. qwik-ssg build --ssg src/entry.ssg.tsx
    • Output information which page was rendered why in which mode
  • SPA mode (only render root page)

Anyways these are just some ideas.

@manucorporat Is there a way to “ask” QwikCity for the configures routes, including dynamic ones?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Static Site Generation (SSG) Overview - Qwik - Builder.io
Static Site Generation, or commonly referred to as "SSG", is the process of pre-rendering site webpages into static HTML files. The benefit is...
Read more >
Basic Features: Pages - Next.js
Next.js has two forms of pre-rendering: Static Generation and Server-side Rendering. The difference is in when it generates the HTML for a page....
Read more >
Static Site Generation - Stencil.js
Static Site Generation (SSG) means building and rendering components and routes at build time (aka prerendering) rather than server request time (SSR) or...
Read more >
What the heck is SSG: Static site generation explained with ...
Static Site Generation a.k.a. SSG is pre-rendering your React app into HTML at build time. SSGvsSSRvsCSR. Let's break it down.
Read more >
Differences Between Static Generated Sites And Server-Side ...
Statically generated sites or pre-rendering and server-side ... A static-site generator (SSG) is a software application that creates HTML ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found