Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use cdn url for static assets (#2281) #2283

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions integrations/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ pub fn html_parts_separated(
options: &LeptosOptions,
meta: Option<&MetaContext>,
) -> (String, &'static str) {
let pkg_path = &options.site_pkg_dir;
let pkg_path = option_env!("CDN_PKG_PATH")
.map(String::from)
.unwrap_or(format!("/{}", options.site_pkg_dir));
zoomiti marked this conversation as resolved.
Show resolved Hide resolved
let output_name = &options.output_name;
let nonce = use_nonce();
let nonce = nonce
Expand Down Expand Up @@ -107,8 +109,8 @@ pub fn html_parts_separated(
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
{head}
<link rel="modulepreload" href="/{pkg_path}/{output_name}.js"{nonce}>
<link rel="preload" href="/{pkg_path}/{wasm_output_name}.wasm" as="fetch" type="application/wasm" crossorigin=""{nonce}>
<link rel="modulepreload" href="{pkg_path}/{output_name}.js"{nonce}>
<link rel="preload" href="{pkg_path}/{wasm_output_name}.wasm" as="fetch" type="application/wasm" crossorigin=""{nonce}>
<script type="module"{nonce}>
function idle(c) {{
if ("requestIdleCallback" in window) {{
Expand All @@ -118,9 +120,9 @@ pub fn html_parts_separated(
}}
}}
idle(() => {{
import('/{pkg_path}/{output_name}.js')
import('{pkg_path}/{output_name}.js')
.then(mod => {{
mod.default('/{pkg_path}/{wasm_output_name}.wasm').then({import_callback});
mod.default('{pkg_path}/{wasm_output_name}.wasm').then({import_callback});
}})
}});
</script>
Expand Down
Loading