[GH-ISSUE #472] feat: support assetPrefix in next.config #103

Open
opened 2026-05-06 12:37:14 +02:00 by BreizhHardware · 0 comments

Originally created by @elydelva on GitHub (Mar 11, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/472

Summary

assetPrefix from next.config is currently not read or used anywhere in vinext. Setting it is silently ignored.

Current behavior

In production, all static assets (fonts, JS chunks, etc.) are always served from:

{basePath}/assets/[file]-[hash].[ext]

The URL is generated by Vite's asset pipeline with no way to inject a CDN prefix.

Expected behavior

When assetPrefix is set in next.config:

// next.config.ts
const nextConfig: NextConfig = {
  assetPrefix: 'https://assets.example.com',
};

All asset URLs should be prefixed accordingly:

https://assets.example.com/assets/Font-[hash].woff2
https://assets.example.com/_next/static/chunks/...

Why this matters

When deploying to Cloudflare Workers with a gateway pattern (a hub Worker routing requests to multiple service Workers), every request — including static assets like fonts and images — goes through the gateway Worker and incurs an invocation.

With assetPrefix support, static assets could be served from a dedicated subdomain (e.g. assets-app.example.com) backed by a Cloudflare Workers Assets-only deployment with run_worker_first: false. This would serve fonts, CSS, and JS bundles directly from Cloudflare's edge with zero Worker invocations.

Investigation

Verified by reading dist/config/next-config.jsresolveNextConfig never extracts assetPrefix. The vinext:local-fonts Vite plugin (index.js lines 3153–3219) rewrites font paths to Vite static asset imports, but Vite's base (driven by basePath) is the only configurable prefix — there is no assetPrefix injection at any stage.

Suggested approach

In resolveNextConfig, extract assetPrefix and pass it through to the Vite plugin. The plugin would then configure Vite's experimental.renderBuiltUrl to prefix resolved asset URLs:

// vite.config equivalent
build: {
  rollupOptions: {},
},
experimental: {
  renderBuiltUrl(filename) {
    return assetPrefix + '/' + filename;
  }
}

This would cover JS/CSS chunks, font files, and images processed through Vite's asset pipeline.

Originally created by @elydelva on GitHub (Mar 11, 2026). Original GitHub issue: https://github.com/cloudflare/vinext/issues/472 ## Summary `assetPrefix` from `next.config` is currently not read or used anywhere in vinext. Setting it is silently ignored. ## Current behavior In production, all static assets (fonts, JS chunks, etc.) are always served from: ``` {basePath}/assets/[file]-[hash].[ext] ``` The URL is generated by Vite's asset pipeline with no way to inject a CDN prefix. ## Expected behavior When `assetPrefix` is set in `next.config`: ```ts // next.config.ts const nextConfig: NextConfig = { assetPrefix: 'https://assets.example.com', }; ``` All asset URLs should be prefixed accordingly: ``` https://assets.example.com/assets/Font-[hash].woff2 https://assets.example.com/_next/static/chunks/... ``` ## Why this matters When deploying to Cloudflare Workers with a gateway pattern (a hub Worker routing requests to multiple service Workers), every request — including static assets like fonts and images — goes through the gateway Worker and incurs an invocation. With `assetPrefix` support, static assets could be served from a dedicated subdomain (e.g. `assets-app.example.com`) backed by a Cloudflare Workers Assets-only deployment with `run_worker_first: false`. This would serve fonts, CSS, and JS bundles **directly from Cloudflare's edge with zero Worker invocations**. ## Investigation Verified by reading `dist/config/next-config.js` — `resolveNextConfig` never extracts `assetPrefix`. The `vinext:local-fonts` Vite plugin (index.js lines 3153–3219) rewrites font paths to Vite static asset imports, but Vite's `base` (driven by `basePath`) is the only configurable prefix — there is no `assetPrefix` injection at any stage. ## Suggested approach In `resolveNextConfig`, extract `assetPrefix` and pass it through to the Vite plugin. The plugin would then configure Vite's [`experimental.renderBuiltUrl`](https://vitejs.dev/guide/build#advanced-base-options) to prefix resolved asset URLs: ```ts // vite.config equivalent build: { rollupOptions: {}, }, experimental: { renderBuiltUrl(filename) { return assetPrefix + '/' + filename; } } ``` This would cover JS/CSS chunks, font files, and images processed through Vite's asset pipeline.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#103
No description provided.