pub struct AssetOptionsBuilder<T> { /* private fields */ }Expand description
A builder for AssetOptions
static ASSET: Asset = asset!(
"/assets/style.css",
AssetOptions::builder()
.with_hash_suffix(false)
);Implementations§
Source§impl AssetOptionsBuilder<FolderAssetOptions>
impl AssetOptionsBuilder<FolderAssetOptions>
Sourcepub const fn into_asset_options(self) -> AssetOptions
pub const fn into_asset_options(self) -> AssetOptions
Convert the options into options for a generic asset
Source§impl AssetOptionsBuilder<ImageAssetOptions>
impl AssetOptionsBuilder<ImageAssetOptions>
Sourcepub const fn with_preload(self, preload: bool) -> Self
pub const fn with_preload(self, preload: bool) -> Self
Make the asset preloaded
Preloading an image will make the image start to load as soon as possible. This is useful for images that will be displayed soon after the page loads or images that may not be visible immediately, but should start loading sooner
const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_preload(true));Sourcepub const fn with_format(self, format: ImageFormat) -> Self
pub const fn with_format(self, format: ImageFormat) -> Self
Sets the format of the image
Choosing the right format can make your site load much faster. Webp and avif images tend to be a good default for most images
const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_format(ImageFormat::Webp));Sourcepub const fn with_avif(self) -> Self
pub const fn with_avif(self) -> Self
Sets the format of the image to ImageFormat::Avif
Avif images tend to be a good default for most images rendered in browser because they compress images well
const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_avif());Sourcepub const fn with_webp(self) -> Self
pub const fn with_webp(self) -> Self
Sets the format of the image to ImageFormat::Webp
Webp images tend to be a good default for most images rendered in browser because they compress images well
const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_webp());Sourcepub const fn with_jpg(self) -> Self
pub const fn with_jpg(self) -> Self
Sets the format of the image to ImageFormat::Jpg
Jpeg images compress much better than ImageFormat::Png, but worse than ImageFormat::Webp or ImageFormat::Avif
const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_jpg());Sourcepub const fn with_png(self) -> Self
pub const fn with_png(self) -> Self
Sets the format of the image to ImageFormat::Png
Png images don’t compress very well, so they are not recommended for large images
const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_png());Sourcepub const fn with_size(self, size: ImageSize) -> Self
pub const fn with_size(self, size: ImageSize) -> Self
Sets the size of the image
If you only use the image in one place, you can set the size of the image to the size it will be displayed at. This will make the image load faster
const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_size(ImageSize::Manual { width: 512, height: 512 }));Sourcepub const fn into_asset_options(self) -> AssetOptions
pub const fn into_asset_options(self) -> AssetOptions
Convert the options into options for a generic asset
Source§impl AssetOptionsBuilder<()>
impl AssetOptionsBuilder<()>
Sourcepub const fn into_asset_options(self) -> AssetOptions
pub const fn into_asset_options(self) -> AssetOptions
Convert the builder into asset options with the given variant
Source§impl<T> AssetOptionsBuilder<T>
impl<T> AssetOptionsBuilder<T>
Sourcepub const fn with_hash_suffix(self, add_hash: bool) -> Self
pub const fn with_hash_suffix(self, add_hash: bool) -> Self
Set whether a hash should be added to the asset path. Manganis adds hashes to asset paths by default for cache busting. With hashed assets, you can serve the asset with a long expiration time, and when the asset changes, the hash in the path will change, causing the browser to fetch the new version.
This method will only effect if the hash is added to the bundled asset path. If you are using the asset macro, the asset struct still needs to be used in your rust code to ensure the asset is included in the binary.
If you are using an asset outside of rust code where you know what the asset hash will be, you must use the
#[used] attribute to ensure the asset is included in the binary even if it is not referenced in the code.
#[used]
static ASSET: manganis::Asset = manganis::asset!(
"/assets/style.css",
manganis::AssetOptions::builder()
.with_hash_suffix(false)
);Source§impl AssetOptionsBuilder<CssAssetOptions>
impl AssetOptionsBuilder<CssAssetOptions>
Sourcepub const fn with_minify(self, minify: bool) -> Self
pub const fn with_minify(self, minify: bool) -> Self
Sets whether the css should be minified (default: true)
Minifying the css can make your site load faster by loading less data
const _: Asset = asset!("/assets/style.css", AssetOptions::css().with_minify(false));Sourcepub const fn with_static_head(self, static_head: bool) -> Self
pub const fn with_static_head(self, static_head: bool) -> Self
Make the asset statically inserted (default: false)
Statically insert the file at compile time.
const _: Asset = asset!("/assets/style.css", AssetOptions::css().with_static_head(true));Sourcepub const fn with_preload(self, preload: bool) -> Self
pub const fn with_preload(self, preload: bool) -> Self
Make the asset preloaded
Preloading css will make the file start to load as soon as possible. This is useful for css that is used soon after the page loads or css that may not be used immediately, but should start loading sooner
const _: Asset = asset!("/assets/style.css", AssetOptions::css().with_preload(true));Sourcepub const fn into_asset_options(self) -> AssetOptions
pub const fn into_asset_options(self) -> AssetOptions
Convert the options into options for a generic asset
Source§impl AssetOptionsBuilder<JsAssetOptions>
impl AssetOptionsBuilder<JsAssetOptions>
Sourcepub const fn with_minify(self, minify: bool) -> Self
pub const fn with_minify(self, minify: bool) -> Self
Sets whether the js should be minified (default: true)
Minifying the js can make your site load faster by loading less data
const _: Asset = asset!("/assets/script.js", AssetOptions::js().with_minify(false));Sourcepub const fn with_static_head(self, static_head: bool) -> Self
pub const fn with_static_head(self, static_head: bool) -> Self
Make the asset statically inserted (default: false)
Statically insert the file at compile time.
const _: Asset = asset!("/assets/script.js", AssetOptions::js().with_static_head(true));Sourcepub const fn with_preload(self, preload: bool) -> Self
pub const fn with_preload(self, preload: bool) -> Self
Make the asset preloaded
Preloading the javascript will make the javascript start to load as soon as possible. This is useful for javascript that will be used soon after the page loads or javascript that may not be used immediately, but should start loading sooner
const _: Asset = asset!("/assets/script.js", AssetOptions::js().with_preload(true));Sourcepub const fn into_asset_options(self) -> AssetOptions
pub const fn into_asset_options(self) -> AssetOptions
Convert the builder into asset options with the given variant
Source§impl AssetOptionsBuilder<CssModuleAssetOptions>
impl AssetOptionsBuilder<CssModuleAssetOptions>
Sourcepub const fn with_minify(self, minify: bool) -> Self
pub const fn with_minify(self, minify: bool) -> Self
Sets whether the css should be minified (default: true)
Minifying the css can make your site load faster by loading less data
Sourcepub const fn with_preload(self, preload: bool) -> Self
pub const fn with_preload(self, preload: bool) -> Self
Make the asset preloaded
Preloading css will make the image start to load as soon as possible. This is useful for css that is used soon after the page loads or css that may not be used immediately, but should start loading sooner
Sourcepub const fn into_asset_options(self) -> AssetOptions
pub const fn into_asset_options(self) -> AssetOptions
Convert the options into options for a generic asset