Ingest Ingest Composable Server/less IO Framework
GitHub

Build Sequence

Lazy Load Routes

Use import routes when a handler should be loaded on demand. They are not only a loading choice; they also give build and deployment tooling explicit visibility into route module boundaries.

Task GuideImplementation Steps

On This Page

Structural Map

  1. Example
  2. Why use this
  3. Read next

Use import routes when a handler should be loaded on demand. They are not only a loading choice; they also give build and deployment tooling explicit visibility into route module boundaries.

Example

TypeScript
app.import.get('/users', () => import('./routes/users.js'));
TypeScript
// ./routes/users.js
export default function UsersIndex({ res }) {
  res.setResults([
    { id: 1, name: 'Ada' },
    { id: 2, name: 'Grace' }
  ]);
}
TypeScript
console.log(app.imports);
// [
//   ['GET /users', [{ priority: 0 }]]
// ]

Why use this

  • reduce initial load
  • expose route import metadata to tooling
  • keep route registration central while loading handlers lazily