Expand description
Like include_dir, but specialized for
serving a directory as a web application.
§Differences from include_dir
- Only files are included. Directories are excluded.
- Paths must be valid UTF-8 without nul characters.
- Path lookup is optimized (using
litemap). - File metadata useful for HTTP caching are computed at build time.
§HTTP Caching Headers
CWebFile fields provide values which can be used for HTTP cache-related
response headers:
ETagis the base32-encoded rapidhash of the file contents.Last-Modifiedis read from the filesystem metadata.Cache-Control: immutablecan be set if the path starts withassets/.
§Immutable Assets
The assumption that files under assets/ should be immutable comes from
the default settings of Vite. Most modern web apps use
Vite as a bundler. Its default settings implement the “cache-busting”
pattern, meaning that static resources will be written to a subpath of
assets/ and a hash will be appended to file names before the file
extension. This pattern makes it possible to cache entire static web
applications on the client web browser.
Re-exports§
pub use litemap;
Macros§
- include_
cwebdir - Embed the contents of a directory in your crate and prepare it for HTTP caching.
Structs§
- CWeb
File - File data with HTTP cache-related metadata.
Type Aliases§
- CWeb
Bundle - Map of paths to files.