bevyengine / bevyengine/bevy

Asset cache busting for web distribution

Open
#21,730 2 comments 0 reactions 0 assignees View on GitHub
A-Assets C-Feature D-Complex O-Web S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## What problem does this solve or what need does it fill?

Currently there seems to be no cache busting (for the browser internal cache) implemented for web asset fetching, which can cause outdated assets to be used after updating them on a hosting service. This might not be critical for textures, but if assets are used for configuration and such, it can be really bad if they are outdated.

## What solution would you like?

### File fingerprinting

The canonical way seems to be to add a hash fingerprint of the contents of each file to its filename. E.g. SvelteKit distribution build transforms `index.js` to `index.C2oOKq9x.js`. This allows hosting services to set a really long `max-age` for the asset while still never serving an outdated file. The hash could also alternatively be added as a query string to the fetch URL, e.g. `https://bevy.com/assets/logo.png?C2oOKq9x`. Then files wouldn't need to be renamed, but the asset reader would just need to add the correct hash to the query string for each file. The browser would then understand when it can and cannot rely on its cache.

This solution can be somewhat complicated, as the hash generation would probably need to be a build script. The most simple solution would probably be to make the `HttpWasmAssetReader` accept a mapping of filenames to hashes (which would be added to the query string). The developer would then need to generate and supply the mapping themselves.

### Versioning

Another simpler, but less efficient way would be to add a game build version string to the query. E.g. `https://bevy.com/assets/logo.png?v=0.9.2`. Then the latest version of the file would be fetched every time the main package version of the game is updated. This is worse than fingerprinting, because all assets are re-fetched even if they didn't change, but really easy to implement.

## What alternative(s) have you considered?

There are hosting tricks that don't require any changes to the engine, but are nonoptimal:
- Disable caching (very inefficient)
- Set a low `max-age`, e.g. 1 hour and setup ETag headers to use fingerprints
- Avoids re-downloading assets, but still needs a network round trip to check each file for changes hourly
- Has an hour window where the assets can be outdated (we want to prevent this)
- This is what itch.io does

## Additional context

Contributor guide

Open the contributing guide

Research direction

Start with the HttpWasmAssetReader and the web asset-fetching path described in the issue. Compare filename fingerprinting, query-string hashes, and version query parameters, including whether a build script or filename-to-hash mapping is needed. Done means browser caching cannot serve outdated web assets after an update without requiring inefficient cache disabling.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.