githubEdit

Progressive Web Apps (PWA)

Turn your Needle Engine project into an installable, offline-capable Progressive Web App with automatic updates and smart caching.

Turn your Needle Engine project into a Progressive Web App with offline support, automatic updates, and installability.

PWA Benefits:

  • 📱 Install on home screen (mobile & desktop)

  • ⚡ Works offline

  • 🔄 Auto-update when you publish new versions

  • 🚀 Faster loading with smart caching

Why would I want a PWA?

  • Tradeshows & events — No reliable internet? No problem. Your 3D experience still works.

  • Kiosks & installations — Install on a device once, runs forever without browser UI

  • Faster repeat visits — Assets are cached, loads instantly after first visit

  • App-like experience — No URL bar, install to home screen, feels like a native app

Setup

1. Install the Vite PWA plugin:

npm install vite-plugin-pwa --save-dev

2. Configure vite.config.js:

Pass the same pwaOptions object to both needlePlugins and VitePWA.

:::tip All assets are cached by default Note that by default, all assets in your build folder are added the PWA precache – for large applications with many dynamic assets, this may not be what you want (imagine the YouTube PWA caching all videos once a user opens the app!). See More PWA Options for how to customize this behavior. :::

Testing PWAs

To test your PWA, deploy the page, for example using the DeployToFTP component. Then, open the deployed page in a browser and check if the PWA features work as expected:

PWAs use Service Workers to cache resources and provide offline support. Service Workers are somewhat harder to use during development, and typically are only enabled for builds (e.g. when you use a DeployTo... component).

You can enable PWA support for development by adding the following to the options object in your vite.config.js.

Please note that PWAs in development mode do not support offline usage – trying it may result in unexpected behavior.

Automatically update running apps

Websites typically show new or updated content on page refresh.

In some situations, you may want the page to refresh and reload automatically when a new version has been published – such as in a museum, trade show, public display, or other long-running scenarios.

To enable automatic updates, set the updateInterval property in the pwaOptions object to a duration (in milliseconds) in which the app should check for updates. If an update is detected, the page will reload automatically.

:::tip Periodic Reloads and User Data It's not recommended to use automatic reloads in applications where users are interacting with forms or other data that could be lost on a reload. For these applications, showing a reload prompt is recommended. See the Vite PWA plugin documentationarrow-up-right for more information on how to implement a reload prompt instead of automatic reloading. :::

Offline use at conventions and exhibitions

PWAs are ideal for trade shows, museums, public displays, and other scenarios where internet connectivity may be unreliable or unavailable. Once a user (or a kiosk device) loads the app while online, all assets are cached locally and the app continues to work fully offline.

Recommended setup for kiosk / convention use:

Tips for reliable offline experiences:

  • Deploy and open the app once while online to let the service worker cache all assets

  • Test offline behavior by disabling the network in Chrome DevTools (Application > Service Workers > Offline)

  • For large scenes with many assets, verify that all files are included in the precache (see More PWA Options)

  • Combine with automatic updates so the display stays current when connectivity returns

Using PWABuilder for validation

PWABuilderarrow-up-right is a Microsoft-developed tool that helps you create and validate PWAs. It can analyze your deployed PWA and provide a score along with recommendations for improvements.

Online Tool:

CLI Version:

Installing PWAs on Different Platforms

Once your PWA is deployed, users can install it on their devices:

Platform
How to Install

Android (Chrome)

Open the website in Chrome → Tap "Install App" or "Add to Home Screen" from the menu

iOS (Safari)

Open the website in Safari → Tap the Share button → Tap "Add to Home Screen"

Windows (Edge/Chrome)

Open the website in Edge/Chrome → Look for the install icon in the address bar → Click "Install"

macOS (Safari/Edge/Chrome)

Open the website → Look for the install icon in the address bar → Click "Install"

:::info PWAs vs Fully Offline Apps PWAs still download assets from the web on first visit, then cache them. If you need a truly offline experience where the app works even without any internet connection from the start (e.g., at a location with no WiFi), consider:

  • makeFilesLocalarrow-up-right — embeds assets directly into the build so they work without network

  • Electron — desktop app wrapping your web content

  • Capacitor — native mobile app from web code :::

More PWA options

Since Needle uses the Vite PWA pluginarrow-up-right under the hood, you can use all options and hooks provided by that. For example, you can provide a partial manifest with a custom app title or theme color:

For complex requirements like partial caching, custom service workers or different update strategies, you can remove the { pwa: pwaOptions } option from needlePlugins and add PWA functionality directly through the Vite PWA plugin.

Making all external files local

By default, Needle Engine loads some assets from CDNs at runtime (e.g. Draco decoders, fonts, skyboxes). For fully self-contained offline deployments, you can use the makeFilesLocal plugin option to download all external assets at build time and bundle them into your output.

This is useful for PWAs that need to work without any network access, and also for non-PWA use cases like playable ads or app store submissions.

Learn more about makeFilesLocal →arrow-up-right

Last updated