feat: add option to statically add js and css assets to the header at compile time (#4653)

Signed-off-by: Omar Mohamed <mohamed.omar67492@gmail.com>
This commit is contained in:
Omar Mohamed Khallaf authored and GitHub committed 2025-10-30 18:55:51 -07:00
1 parent 3f931e8409
commit a4d1fd848d
3 files changed
+67 -10

No files matched your search

+24 -9
View File
@@ -4886,23 +4886,38 @@ __wbg_init({{module_or_path: "/{}/{wasm_path}"}}).then((wasm) => {{
match asset.options().variant() {
AssetVariant::Css(css_options) => {
if css_options.preloaded() {
head_resources.push_str(&format!(
"<link rel=\"preload\" as=\"style\" href=\"/{{base_path}}/assets/{asset_path}\" crossorigin>"
))
_ = write!(
head_resources,
r#"<link rel="preload" as="style" href="/{{base_path}}/assets/{asset_path}" crossorigin>"#
);
}
if css_options.static_head() {
_ = write!(
head_resources,
r#"<link rel="stylesheet" href="/{{base_path}}/assets/{asset_path}" type="text/css">"#
);
}
}
AssetVariant::Image(image_options) => {
if image_options.preloaded() {
head_resources.push_str(&format!(
"<link rel=\"preload\" as=\"image\" href=\"/{{base_path}}/assets/{asset_path}\" crossorigin>"
))
_ = write!(
head_resources,
r#"<link rel="preload" as="image" href="/{{base_path}}/assets/{asset_path}" crossorigin>"#
);
}
}
AssetVariant::Js(js_options) => {
if js_options.preloaded() {
head_resources.push_str(&format!(
"<link rel=\"preload\" as=\"script\" href=\"/{{base_path}}/assets/{asset_path}\" crossorigin>"
))
_ = write!(
head_resources,
r#"<link rel="preload" as="script" href="/{{base_path}}/assets/{asset_path}" crossorigin>"#
);
}
if js_options.static_head() {
_ = write!(
head_resources,
r#"<script src="/{{base_path}}/assets/{asset_path}"></script>"#
);
}
}
_ => {}