Skip to content

docs: add CDN-agnostic Asset CDN Setup guide#576

Open
anvme wants to merge 1 commit into
chatwoot:mainfrom
anvme:docs/asset-cdn-setup
Open

docs: add CDN-agnostic Asset CDN Setup guide#576
anvme wants to merge 1 commit into
chatwoot:mainfrom
anvme:docs/asset-cdn-setup

Conversation

@anvme
Copy link
Copy Markdown

@anvme anvme commented May 27, 2026

Companion to chatwoot/chatwoot#14581 (fix #13687).

The existing CloudFront CDN guide only covers AWS-specific distribution setup. Self-hosters who want to use a different CDN (Bunny, Cloudflare R2, custom origin, etc.) currently have to reverse-engineer the upload workflow themselves: which public/ subdirectories matter, which files must stay same-origin, how ASSET_CDN_HOST propagates at runtime, and what CORS setup the chosen CDN topology requires.

This PR adds a CDN-agnostic Asset CDN Setup guide and links to it from the CloudFront CDN guide (for the asset-upload mechanics, since the CloudFront page focuses on the distribution wizard) and the environment-variables mention of ASSET_CDN_HOST.

It also updates cloudfront-cdn.mdx's CORS troubleshooting section: the old text recommended setting CORS_ORIGINS (which controls API CORS for /api/*, unrelated to asset delivery). Replaced with a correct pull-CDN vs object-storage breakdown that links to the new full CORS section.

What it covers

  • Inventory of which directories under public/ belong on the CDN, including root-level favicons/PWA icons and browserconfig.xml.
  • Same-origin exceptions (sw.js, manifest.json) with the spec citations: Service Worker spec requires same-origin script URL; PWA start_url resolves relative to the manifest URL.
  • No rebuild required: fix: Fixes #13687 — honor ASSET_CDN_HOST across Vite chunks, hardcoded asset paths, the embed SDK, and backend asset emitters chatwoot#14581 switches Vite to runtime base resolution via experimental.renderBuiltUrl + a server-injected window.__VITE_BASE__ script. The same pre-built chatwoot/chatwoot:latest image works for any ASSET_CDN_HOST value — flip it in .env, restart, done.
  • Extract → upload workflow with per-provider examples (Bunny Storage API including root-file upload, AWS S3+CloudFront with stable-URL invalidation, rsync over SSH).
  • Runtime configuration: ASSET_CDN_HOST only; how Rails + Vite + the SDK snippet emitter all read it.
  • CORS section covering three deployment shapes:
    1. Pull CDN proxying the Rails origin — Chatwoot ships the asset-path allowlist in config/initializers/cors.rb, no CDN-side CORS config needed.
    2. CDN hostname CNAME'd directly to the Rails origin (e.g., during a CDN migration when traffic temporarily skips the CDN) — same Rails allowlist handles it.
    3. Object-storage CDN (S3, R2, Bunny Storage, GCS) — Rails is not in the request path, so CORS must be set at the storage layer. Per-provider config paths included.
    • Plus a footnote on nginx/Apache fronting /public (CORS must come from the proxy in that case).
  • Updating assets after a release: don't delete old hashed chunks for 24h, invalidate stable URLs (/packs/js/sdk.js, audio, favicons, brand-assets), hashed Vite chunks need no invalidation.
  • Troubleshooting: LAN firewall (and the "no per-surface CDN toggle" caveat), "assets still on Rails origin" diagnostic checklist, hand-rolled widget snippet two-piece fix (g.src + cdnUrl).

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 83ecf6c8f0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread self-hosted/deployment/performance/asset-cdn-setup.mdx Outdated
Comment thread self-hosted/deployment/performance/asset-cdn-setup.mdx Outdated
@anvme anvme force-pushed the docs/asset-cdn-setup branch from 83ecf6c to bb404e0 Compare May 27, 2026 17:30
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb404e071b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread self-hosted/deployment/performance/asset-cdn-setup.mdx Outdated
@anvme anvme force-pushed the docs/asset-cdn-setup branch from bb404e0 to f2bd31b Compare May 27, 2026 17:40
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f2bd31bf50

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread self-hosted/deployment/performance/asset-cdn-setup.mdx Outdated
@anvme anvme force-pushed the docs/asset-cdn-setup branch from f2bd31b to 7997c8c Compare May 27, 2026 17:47
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7997c8c19d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread self-hosted/deployment/performance/asset-cdn-setup.mdx
@anvme anvme force-pushed the docs/asset-cdn-setup branch from 7997c8c to 647ed3a Compare May 27, 2026 17:55
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 647ed3a756

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread self-hosted/deployment/performance/asset-cdn-setup.mdx Outdated
@anvme anvme force-pushed the docs/asset-cdn-setup branch from 647ed3a to f44fbd1 Compare May 27, 2026 18:20
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f44fbd16de

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread self-hosted/deployment/performance/asset-cdn-setup.mdx Outdated
@anvme anvme force-pushed the docs/asset-cdn-setup branch from f44fbd1 to 0014713 Compare May 27, 2026 18:30
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 00147135d1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread self-hosted/deployment/performance/cloudfront-cdn.mdx
Companion to chatwoot/chatwoot#14581 (fix #13687). The existing
cloudfront-cdn page only covers AWS-specific distribution config and
doesn't explain the asset-upload workflow that any CDN deployment needs:

- which public/ subdirectories to publish
- which files (sw.js, manifest.json) must stay same-origin and why
- the docker --build-arg ASSET_CDN_HOST step that bakes the host into
  Vite chunks at build time
- runtime ASSET_CDN_HOST + CORS_ORIGINS
- per-provider upload commands (Bunny, S3+CloudFront, rsync)
- common troubleshooting (LAN firewall, assets-fetched-twice, widget
  snippet missing cdnUrl)

The new generic page sits alongside cloudfront-cdn in the Performance
nav group. The CloudFront guide and the environment-variables CDN
blurb now link to it for upload mechanics so the AWS-specific page
can stay focused on the distribution wizard.
@anvme anvme force-pushed the docs/asset-cdn-setup branch from 0014713 to e09e478 Compare May 27, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant