Web Hosting
A build is a folder of static files, so any web server or static hosting service can serve it. Nothing runs on the server. The browser downloads index.html, which loads the engine, your code and your assets.
To get a build, see Making a Build. For an Editor project, PlayCanvas Hosting is the quickest option, with nothing to set up.
Testing a Build Locally
A build doesn't run if you open its index.html file in a browser by double-clicking it. Browsers block a page opened from a file:// URL from loading the files it needs, so serve the folder from a local web server instead:
- Vite projects: run
npm run build, thennpx vite preview. In a create-playcanvas project,npm startdoes the same and opens the build in your browser. - Any build folder: run
npx servein the folder, which needs Node.js, orpython3 -m http.server, which needs Python. Then open the address it prints, such ashttp://localhost:3000.
Choosing a Host
Any host that serves static files works. For example:
- Static hosting services, such as GitHub Pages, Netlify, Cloudflare Pages and Vercel, publish a folder that you upload or push to a Git repository. They serve it from a content delivery network (CDN), with compression and caching already set up.
- Game portals, such as itch.io, accept a zip file of the build. Publishing lists the platforms that have their own page.
- Your own web server, such as Apache, nginx or IIS, serves the build like any other static site. See Configuring Your Server.
If the build lives in a subfolder of a site rather than at the root of a domain, as a GitHub Pages project site does, it must load its files with relative URLs. Editor builds and create-playcanvas projects already do. In other Vite projects, set Vite's base option to './'.
GitHub Pages
By default, GitHub Pages builds a site with Jekyll, which leaves out files whose names start with an underscore. Editor builds of projects with Classic scripts contain files like __start__.js, so add an empty file named .nojekyll to the root of the build. Publishing with a GitHub Actions workflow, as Vite's deployment guide describes, skips Jekyll.
Configuring Your Server
Static hosting services take care of these settings. On your own server, check each one.
Compression
Turn on gzip or Brotli compression for .html, .js, .mjs, .css, .json and .wasm files. Engine code and scene files are large text files that compress to a fraction of their size, so this matters more than any other setting. Images, audio and video files are already compressed.
Caching
Some files keep their names from one build to the next, such as index.html. Send them with the Cache-Control: no-cache header, so browsers check for a newer version each time. Otherwise players can keep seeing an old build after you upload a new one.
Files whose names change when their contents change, such as the hashed files Vite writes to dist/assets/, can be cached for a long time.
Content Types
Make sure the server sends the right Content-Type header for each file. Browsers refuse to run a JavaScript module sent with any type but text/javascript, and they compile WebAssembly while it downloads only when it's sent as application/wasm. Most servers know the common types, but older ones may not know .mjs, .wasm, .glb or .ktx2.
| Extension | Content type |
|---|---|
.html | text/html |
.js, .mjs | text/javascript |
.css | text/css |
.json | application/json |
.wasm | application/wasm |
.glb | model/gltf-binary |
.gltf | model/gltf+json |
.bin, .basis | application/octet-stream |
.ktx2 | image/ktx2 |
.png | image/png |
.jpg, .jpeg | image/jpeg |
.webp | image/webp |
.mp3 | audio/mpeg |
.ogg | audio/ogg |
.wav | audio/wav |
.mp4 | video/mp4 |
.webm | video/webm |
Serving Assets from a CDN
Static hosting services already serve the whole build from a CDN. If you serve index.html from your own server, you can still load the larger files, such as models and textures, from a CDN or another server:
- Upload the whole build folder to the CDN, keeping its folder structure, so that every file the app looks for there exists.
- Set up Cross-Origin Resource Sharing (CORS) on the CDN. A page can only load files from another origin, such as
https://cdn.example.comfor a page onhttps://example.com, if that server allows it with theAccess-Control-Allow-Originheader. Set it to your site's origin, or to*to allow any site. Each CDN sets it in its own way, so see its documentation, for example Amazon S3. - Tell the app where to find its assets, as described below.
- Editor
- Engine
- React
- Web Components
An Editor build loads its assets, scene files and loading screen logo from the address in ASSET_PREFIX, which is empty by default:
- With Classic scripts, it's in
__settings__.js:window.ASSET_PREFIX = ""; - With ESM scripts, it's near the start of
js/index.mjs:const ASSET_PREFIX="";
Set it to the address of the build folder on the CDN, ending with /, such as "https://cdn.example.com/my-game/".
Set the asset registry's prefix before you load any assets:
app.assets.prefix = 'https://cdn.example.com/my-game/';
The engine adds the prefix to the start of every relative asset and scene URL. Absolute URLs load unchanged.
Load assets from absolute URLs on the CDN:
const { asset } = useModel('https://cdn.example.com/my-game/level.glb');
Load assets from absolute URLs on the CDN:
<pc-asset id="level" src="https://cdn.example.com/my-game/level.glb"></pc-asset>