13 releases
| new 0.7.3 | Jan 17, 2026 |
|---|---|
| 0.7.2 | Dec 5, 2025 |
| 0.7.1 | Nov 6, 2025 |
| 0.7.0 | Oct 31, 2025 |
| 0.7.0-alpha.1 | May 31, 2025 |
#1886 in Web programming
35,805 downloads per month
Used in 47 crates
(5 directly)
28KB
342 lines
The asset resolver for the Dioxus bundle format. Each platform has its own way of resolving assets. This crate handles resolving assets in a cross-platform way.
There are two broad locations for assets depending on the platform:
- Web: Assets are stored on a remote server and fetched via HTTP requests.
- Native: Assets are read from the local bundle. Each platform has its own bundle structure which may store assets as a file at a specific path or in an opaque format like Android's AssetManager.
read_asset_bytes( abstracts over both of these methods, allowing you to read the bytes of an asset
regardless of the platform.
If you know you are on a desktop platform, you can use asset_path to resolve the path of an asset and read
the contents with std::fs.
Example
use dioxus::prelude::*;
// Bundle the static JSON asset into the application
static JSON_ASSET: Asset = asset!("/assets/data.json");
// Read the bytes of the JSON asset
let bytes = dioxus::asset_resolver::read_asset_bytes(&JSON_ASSET).await.unwrap();
// Deserialize the JSON data
let json: serde_json::Value = serde_json::from_slice(&bytes).unwrap();
assert_eq!(json["key"].as_str(), Some("value"));
Dependencies
~0.2–15MB
~146K SLoC