Assets
Overview of asset types and storage options (local or online) in Pixi’VN, with usage examples.
Assets are all files that are not code, such as images, sounds, and videos.
Assets can be stored locally inside the project or hosted online. Frequently used assets — such as character sprites, backgrounds, and background music — are best kept local. Assets used only once or large optional files are better hosted online. Each approach has trade-offs:
Local assets
To save and use assets locally, you can use any folder—there are no restrictions. However, it is recommended to use the src/assets folder. Inside this folder, you can create subfolders to better organize your assets.
PixiJS AssetPack is a tool for optimizing local assets for the web. It can be used to transform, combine, and compress assets.
You can learn more about PixiJS AssetPack on the PixiJS website.
PixiJS AssetPack is already pre-configured in the Pixi’VN project templates through the Vite.js integration — automating the processing and optimization of your assets so you can focus on building your project.
During development (vite dev) it watches the src/assets folder for changes and processes them on the fly. During the production build (vite build) it runs a full optimization pass before bundling.
The optimizations it applies include:
- Compression — reduces file sizes for faster loading.
- Format conversion — converts images to modern formats (e.g. WebP, AVIF) when supported.
- Texture atlases — combines multiple small images into a single sprite sheet to reduce draw calls.
Once processing is complete, it generates optimized files in public/assets and the src/assets/manifest.gen.json file, which contains the list of all asset bundles and their paths. These outputs are then used by PixiJS to load assets efficiently.
{
"bundles": [
{
"name": "audio",
"assets": [
{
"alias": "bgm_cheerful",
"src": "./assets/audio/bgm_cheerful.wav"
},
{
"alias": "sfx_whoosh",
"src": "./assets/audio/sfx_whoosh.wav"
}
]
},
{
"name": "mainmenu",
"assets": [
{
"alias": "background_main_menu",
"src": "./assets/mainmenu/background_main_menu.png"
}
]
},
{
"name": "start",
"assets": [
{
"alias": "bg01-hallway",
"src": "./assets/start/bg01-hallway.webp"
}
]
},
{
"name": "mc",
"assets": [
{
"alias": "mc-neutral",
"src": "./assets/mc/mc-neutral.png"
}
]
}
]
}Assets hosting
You can save your assets online. This is a good option if you want to save space in your project or if you want create a game playable online without the need to download it first. You can use any cloud service that allows you to upload files and generate a public URL (you need to make sure that the cloud service you are using allows CORS requests).
Here are some popular options for hosting your assets online:
You can use Github to host your assets. You can use the raw link of the file in your project. The link will be in the following format:
https://raw.githubusercontent.com/[repository]/raw/refs/heads/main/[file path]- Price: Completely free.
- Space limits: No space limits, but each single file must not exceed 100 MB.
- Type of files: You can upload any type of file.
- Traffic: Speed is not the best.
- Edit assets: You can edit the file while keeping the same URL.
Image hosting is a service that allows you to upload images. There are many sites to upload images for free, for example imgbb, imgix, imgur. You can use the link of the image in your project.
- Price: Completely free, but you can pay for more features.
- Space limits: No space limits, but each single file can have a maximum size.
- Type of files: You can upload only images.
- Traffic: Speed is good.
- Edit assets: You can't edit the file while keeping the same URL.
Cloud storage is a service that allows you to upload any type of file online. There are many popular options, for example Cloudflare R2, Firebase Storage, Amazon S3, Supabase, Convex.
- Price: Usually paid or with a free version with limits.
- Space limits: Monthly cost based on space used (usually free if you do not exceed a certain threshold).
- Type of files: You can upload any type of file.
- Traffic: Speed is good.
- Edit assets: You can edit the file while keeping the same URL.
Once you have your assets ready, you need to manually define which ones your game can use and how they are grouped into bundles.
It is strongly recommended to follow the asset loading best practices to minimize loading times and avoid blocking the game unnecessarily.
All Pixi’VN templates include a src/assets/index.ts file that you can edit to register your assets:
import generatedManifestJson from "@/assets/manifest.gen.json";
import { AUDIO_BUNDLE_NAME } from "@/constants";
import { startLabel } from "@/content/labels/start.label";
import type { FileRouteTypes } from "@/routeTree.gen";
import type { AssetsManifest } from "@drincs/pixi-vn";
export const manifest: AssetsManifest = {
bundles: [
...generatedManifestJson.bundles,
{
name: AUDIO_BUNDLE_NAME,
assets: [
{
alias: "bgm_cheerful",
src: "https://raw.githubusercontent.com/user/project/refs/heads/main/audio/bgm_cheerful.wav",
},
{
alias: "sfx_whoosh",
src: "https://raw.githubusercontent.com/user/project/refs/heads/main/audio/sfx_whoosh.wav",
},
],
},
// screens
{
// main menu
name: "/" as FileRouteTypes["fullPaths"],
assets: [
{
alias: "background_main_menu",
src: "https://raw.githubusercontent.com/user/project/refs/heads/main/main-menu.png",
},
],
},
// labels
{
name: startLabel.id,
assets: [
{
alias: "bg01-hallway",
src: "https://raw.githubusercontent.com/user/project/refs/heads/main/breakdown/bg01-hallway.webp",
},
],
},
// characters
{
name: "mc",
assets: [
{
alias: "mc-neutral",
src: "https://raw.githubusercontent.com/user/project/refs/heads/main/characters/mc-neutral.png",
},
],
},
],
};Other features
Templates
In all templates, assets loaded from external URLs are automatically cached by the service worker for offline use. This is configured in the vite.config.ts file using the vite-plugin-pwa plugin.
For online games, caching external assets is crucial: it avoids re-downloading the same files on every session, reduces latency, and allows the game to work even when the connection is temporarily unavailable.
This is handled by VitePWA, which is pre-configured in the templates. You can customize the caching behavior directly in vite.config.ts:
CACHED_EXTERNAL_HOSTNAMES— list of external hostnames whose assets should be cached. Add any CDN or remote host you use.cacheableResponse— defines which HTTP responses are eligible for caching (e.g. status0for opaque responses and200for successful ones).expiration— controls how long cached assets are kept. By default assets are cached for 7 days (maxAgeSeconds: 7 * 24 * 60 * 60).
import { defineConfig } from "vite";
import { VitePWA } from "vite-plugin-pwa";
/**
* List of external hostnames whose responses should be cached by the service worker.
* Add any CDN or remote asset host here to enable offline caching for it.
* Examples:
* "cdn.jsdelivr.net"
* "your.cdn.domain.com"
*/
const CACHED_EXTERNAL_HOSTNAMES: string[] = ["raw.githubusercontent.com"];
export default defineConfig(() => ({
plugins: [
VitePWA({
// ...
workbox: {
runtimeCaching: [
{
urlPattern: ({ url }) =>
CACHED_EXTERNAL_HOSTNAMES.includes(url.hostname),
handler: "CacheFirst",
options: {
cacheName: "external-assets-v1",
cacheableResponse: {
statuses: [0, 200],
},
expiration: {
maxAgeSeconds: 7 * 24 * 60 * 60,
},
},
},
],
},
}),
],
}));