Quick Start
Add the web dependency to yourCargo.toml:
Architecture
WebAssembly Rendering
The web renderer uses a hybrid approach:- Sledgehammer: A custom binary protocol for efficient DOM mutations
- web-sys: Direct bindings to browser APIs
- Template caching: Templates are serialized once and cloned on demand
Bundle Size
The Dioxus web runtime is approximately 60KB gzipped, making it competitive with other modern frameworks.Configuration
Customize the web renderer with theConfig struct:
Configuration Options
- rootname: Set the ID of the root element (default: “main”)
- rootelement: Use a specific DOM element as root
- hydrate: Enable server-side rendering hydration
- history: Configure the history provider (WebHistory or HashHistory)
Browser APIs
Accessing web-sys
You can access browser APIs directly using web-sys:Local Storage
Web Workers
Use web workers for background processing:Server-Side Rendering
The web renderer supports hydration from server-rendered HTML:Hot Reloading
The web renderer includes instant hot-reloading via the Dioxus CLI:Event Handling
Event Delegation
The web renderer uses event delegation for efficiency:- Single listener on the root element
- Events bubble up and are matched by
data-dioxus-id - Supports all standard DOM events
Custom Events
Access raw web events when needed:Performance Tips
1. Use Signals for Fine-Grained Reactivity
2. Memoize Expensive Computations
3. Lazy Load Components
Use dynamic imports for code splitting:Deployment
Building for Production
dist/ directory.
Hosting
Serve the built files with any static file server:- GitHub Pages
- Netlify
- Vercel
- Cloudflare Pages
- AWS S3 + CloudFront
Debugging
Console Logging
tracing crate with tracing-wasm:
Browser DevTools
- Enable source maps in development
- Use browser debugger with Rust source
- Inspect WASM memory and performance
Next Steps
- Desktop Platform - Build native desktop apps
- Router - Add navigation to your web app
- Fullstack - Combine client and server