How toUse a CDN for your static assets in Remix

Let's say you're deploying your Remix app somewhere, and you want to upload your public folder to some CDN that will work under, while your app runs on

We can tell Remix that every link to your public files (JS files, images, fonts, CSS, etc.) will be loaded from that URL by using the publicPath option in the remix.config.mjs.

/** @type {import('@remix-run/dev').AppConfig} */ export default { publicPath: getPublicPath(), // other options }; function getPublicPath() { let defaultCDN = ""; let isCI = process.env.CI || false; if (!isCI) return "/build/"; return `${defaultCDN}/build/`; }

With this, when we run remix build in a CI process it will use the path for every public file our app links to, and locally it will just use /build/.