Deploying Rust and WebAssembly to Production
⚡ Deploying Web applications built with Rust and WebAssembly is nearly identical to deploying any other Web application!
To deploy a Web application that uses Rust-generated WebAssembly on the client,copy the built Web application's files to your production server's file systemand configure your HTTP server to make them accessible.
Ensure that Your HTTP Server Uses the application/wasm MIME Type
For the fastest page loads, you'll want to use theWebAssembly.instantiateStreaming
function to pipelinewasm compilation and instantiation with network transfer (or make sure yourbundler is able to use that function). However, instantiateStreaming
requiresthat the HTTP response has the application/wasm
MIME type set, or else itwill throw an error.
- How to configure MIME types for the Apache HTTP server
- How to configure MIME types for the NGINX HTTP server
More Resources
- Best Practices for Webpack in Production. Many Rust andWebAssembly projects use Webpack to bundle their Rust-generated WebAssembly,JavaScript, CSS, and HTML. This guide has tips for getting the most out ofWebpack when deploying to production environments.
- Apache documentation. Apache is a popular HTTP server for use inproduction.
- NGINX documentation. NGINX is a popular HTTP server for use inproduction.