Nue.js (nuejs.org) is a modern static site generator (SSG) designed to simplify web development by emphasizing separation of concerns, progressive enhancement, and a content-first philosophy. Here’s a detailed breakdown of how its SSG works, based on its core principles and features:
1. Content-First Development
Nue uses an extended Markdown syntax (Nuemark) as the foundation for building pages. This syntax supports:
-
Dynamic variables: Embed data like
{ package.name }directly in Markdown. -
Custom components: Inline reusable components (e.g.,
[custom-tag]) within content. -
Semantic structure: Automatic section splitting using
h2or---separators, and explicit heading IDs/classes (e.g.,## Section { #id.class }). -
Interactive elements: Integrate components like accordions, tabs, and popovers via tags like
[accordion]or[button popovertarget].
The content is parsed using a custom Markdown parser with a mutable abstract syntax tree (AST), enabling advanced manipulation and extensions before rendering clean HTML optimized for SEO and accessibility.
2. Progressive Enhancement
Nue’s SSG generates static HTML upfront and progressively enhances it:
-
Interactive Islands: Only specific components (like forms or dynamic widgets) are hydrated with JavaScript, reducing client-side overhead. These can be vanilla web components, isomorphic components (server + client rendering), or lightweight reactive elements.
-
Turbolinking & View Transitions: Pre-rendered pages load instantly via turbolinking, while CSS-based view transitions (e.g.,
view-transition-name) enable smooth page switches. -
CSS Inlining: Critical CSS is inlined to ensure immediate rendering, minimizing render-blocking requests.
3. Performance Optimization
Nue prioritizes speed and minimalism:
-
Lightweight Output: Pages are rendered with tiny payloads (e.g., 19kB total for documentation vs. 644kB for Next.js).
-
Fast Builds: Incremental builds take milliseconds per page due to a dependency-free architecture. For example, 100 pages build in ~0.1 seconds.
-
Hot Reloading: Changes to content, layouts, or styles are detected instantly, with hot-reload times as low as 0.05 seconds.
4. Design Engineering Focus
Nue shifts the focus from JavaScript engineering to design systems:
-
Semantic HTML: Clean markup ensures compatibility with screen readers and search engines.
-
Modern CSS: Styles are decoupled from JavaScript, leveraging CSS modules and global styles without conflicts.
-
Motion Design: Built-in support for CSS animations and transitions (e.g., scroll-triggered effects) enhances UX without heavy JS libraries.
5. Comparison with Next.js
Unlike monolithic frameworks like Next.js, Nue avoids complex abstractions (e.g., hooks, virtual DOM) and reduces dependencies:
-
Smaller Codebase: Nue uses ~10 NPM modules vs. 300+ in Next.js.
-
Simpler Architecture: No client-side hydration for static content, eliminating runtime overhead.
-
Focus on Standards: Relies on native browser features (e.g., Web Components, CSS) instead of framework-specific solutions.
Example Workflow
-
Content Creation: Write pages in Nuemark with embedded variables and components.
-
Build Process: Generate static HTML, CSS, and JS islands at build time.
-
Deployment: Serve pre-rendered pages with incremental enhancements (e.g., interactive islands) as needed.
For developers, this means faster iterations, better maintainability, and a stronger emphasis on design and content quality. To explore further, see Nue’s documentation and release notes.