BrowserUX Inject SW Assets
A simple and effective solution to ensure full offline support in your Vite + PWA applications.
BrowserUX Inject SW Assets is a lightweight and smart Vite plugin designed to automatically inject your static files (images, JSON, etc.) into your custom service worker. It perfectly complements the injectManifest strategy from vite-plugin-pwa by making sure all files not detected by Workbox are properly precached. It provides a complete offline experience, with no complex configuration or overlooked assets.
Plugin for Vite
See the CHANGELOG
npm install vite-plugin-inject-sw-assets
Features
-
-
ποΈ Automatically scans the
dist/folder at the end of the build to detect static files - πΌοΈ Automatically includes image, icon, JSON, font files, etc., based on their extension (configurable)
-
π Smartly ignores files already listed in
manifest.webmanifest(e.g. PWA icons) -
π§Ύ Generates a
sw-assets.jsfile ready to be imported into a custom service worker -
π§° Easily customizable via
extensions,distDir,output, andexcludeFromManifest
-
ποΈ Automatically scans the
-
-
π¦ Fully compatible with any Vite + PWA workflow using
injectManifest - π« Prevents offline 404 errors for images or JSON files referenced in HTML
- π― Automates a commonly forgotten step in custom service worker setups
- π§Ό No HTML changes required β everything is handled at build time
-
π Works seamlessly with
vite-plugin-pwa, in addition to__WB_MANIFEST - π οΈ Works with all Vite projects: React, Vue, Svelte, Vanilla, and more
-
π¦ Fully compatible with any Vite + PWA workflow using