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

Support CDN baseUrl in <Script> #211

Open
tkkrr opened this issue Aug 5, 2024 · 0 comments
Open

Support CDN baseUrl in <Script> #211

tkkrr opened this issue Aug 5, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@tkkrr
Copy link

tkkrr commented Aug 5, 2024

What is the feature you are proposing?

I am going to use the Honox on the Node.js runtime.
I want to serve hydration Javascript files (/static/*.js) from a different host (i.e., CDN) from the Node.js server for SSR.

e.g.,

const baseUrl = import.meta.env.PROD ? "https://cdn.mydomain.com/" : "/": 

export default jsxRenderer(({ children, title }) => {
  return (
    <html lang="en">
      <head>
        <title>{title}</title>
        {/* change baseurl */}
        <Script src="/app/client.ts" baseurl={baseUrl} async />
        <Style />
      </head>
      <body>{children}</body>
    </html>
  )
})

FYI: like assetPrefix on next.config.js (Next.js)
https://nextjs.org/docs/app/api-reference/next-config-js/assetPrefix

const isProd = process.env.NODE_ENV === 'production'
 
module.exports = {
  // Use the CDN in production and localhost for development.
  assetPrefix: isProd ? 'https://cdn.example.com' : undefined,
}
@tkkrr tkkrr added the enhancement New feature or request label Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant