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

How to Use CDN Url for Static Assets When Deploying with SSR? #2281

Closed
CodingFlow opened this issue Feb 8, 2024 · 2 comments · Fixed by #2283
Closed

How to Use CDN Url for Static Assets When Deploying with SSR? #2281

CodingFlow opened this issue Feb 8, 2024 · 2 comments · Fixed by #2283

Comments

@CodingFlow
Copy link

When deploying using SSR, I would like to specify an absolute path for all static client-side assets, including the initial client-side java-script file and wasm file. This will allow using a CDN for static assets. Currently, I have not found a way to alter the relative paths for static assets; a preceding slash / is always added. I'm using the start-aws template. Is there a way to accomplish this?

@gbj gbj transferred this issue from leptos-rs/cargo-leptos Feb 9, 2024
@gbj
Copy link
Collaborator

gbj commented Feb 9, 2024

I transferred this issue into the main repo because it's not related to cargo-leptos, but rather the glue code injected by the server integrations. It should be perfectly possible to introduce some logic here that does something like "at compile time, look for an environment variable named CDN_PKG_PATH and use that instead of &option.site_pkg_dir.

#[tracing::instrument(level = "trace", fields(error), skip_all)]
pub fn html_parts_separated(
options: &LeptosOptions,
meta: Option<&MetaContext>,
) -> (String, &'static str) {
let pkg_path = &options.site_pkg_dir;
let output_name = &options.output_name;

let head = format!(
r#"<!DOCTYPE html>
<html{html_metadata}>
<head>
<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}>

Any interest in making a PR?

@zoomiti
Copy link
Contributor

zoomiti commented Feb 9, 2024

I decided to pick up this because it should be a short and sweet PR. Just to clarify though, the env var should be checked at compile time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants