Docs
/
Tooling
/
SSG/SSR

SSG/SSR

Server-Side Rendering (SSR)

Million.js is a great choice if you want to implement Hot Module Replacement (HMR) for your framework. An example usage of HMR refresh function can be seen here:

import { refresh } from 'million/ssr';

refresh(
  `<head>
    <title>World</title>
  </head>`,
  `<body>
    <p>Hello World</p>
    <p>Goodbye World</p>
  </body>`,
);

If you're dealing with components, you can attach a ignore prop to the component's attributes. This will prevent the component from being re-rendered when the refresh function is called.

import { refresh } from 'million/ssr';

refresh(
  undefined,
  `<body>
    <p ignore>Not rendered</p>
  </body>`,
);

Server-Side Generation (SSG)

Million.js is intended to be the Virtual DOM runtime for your application. It's primarily designed to be augmented by a compiler which can produce optimizations and code generation for Million.js. However, Million doesn't provide a compiler by default, as static analysis and code generation are difficult to pull off well without knowledge of the library (state, components, etc.).

However, Million does provide example implementations for virtual node h functions to raw objects with vite-plugin-million.

If you are considering writing a compiler for your Million library, consider taking a look at the implemenation of vite-plugin-million. Additionally, you should look into recast and ast-types, both great options for JavaScript AST traversal for static analysis. The reference for the AST can be found with the ESPrisma documentation