Linux Kernel & OS

Topcoat framework enables server-side web rendering using Rust

Key Takeaway

Topcoat allows Rust developers to build web applications by compiling Rust to JavaScript for the browser while performing heavy logic and database interactions on the server.

Summary

Carl Lerche, creator of the Tokio asynchronous runtime, has introduced Topcoat, a new framework designed to bring Rust to the mainstream of web development. Unlike existing Rust frameworks like Leptos or Dioxus that rely on WebAssembly, Topcoat focuses on server-side rendering (SSR) to improve initial load times and reduce browser overhead.

The framework targets the majority of standard, database-driven web applications by executing most logic on the server and delivering HTML snippets to the client. This approach minimizes the amount of program logic sent to the browser, instead using a subset of Rust that is automatically compiled into JavaScript to handle DOM interactions.

Technical architecture of Topcoat

  • Compilation Strategy: Instead of using WebAssembly for the entire frontend, Topcoat compiles a subset of Rust code into JavaScript to maintain efficient interaction with the browser's Document Object Model (DOM).
  • Server-Side Rendering (SSR): The framework utilizes a component-based SSR model where user actions trigger the server to return specific HTML snippets rather than performing full page refreshes.
  • Data Integration: Topcoat integrates with Toasty, an asynchronous Rust-based object-relational mapper (ORM), allowing server-side components to communicate directly with databases without manual serialization or deserialization steps.
  • Streaming and Loading: The system supports non-blocking data loading by sending HTML templates with placeholders, allowing the browser to preload assets like CSS and images while data streams into the page.

Why it matters

Why it matters: Topcoat provides a high-performance alternative for Rust developers who want to avoid the heavy payload of WebAssembly-based frameworks. By bridging the gap between Rust's backend safety and JavaScript's frontend ubiquity, it offers a path for building scalable, database-driven web services with reduced latency.

Original reference: www.theregister.com →