All Topics
All Topics
Technology
Technology
AI
AI
Business
Business
Entertainment
Entertainment
News
News
Programming
Programming
Security
Security
Science
Science
Design
Design
Environment
Environment
Finance
Finance
Crypto
Crypto
Politics
Politics
Sports
Sports
Education
Education
Gaming
Gaming
Art
Art
Music
Music
Health
Health
Books
Books
Food
Food
Travel
Travel
Personal
Personal
Bluesky
Twitter

Workers - Enhanced support for static assets with the Cloudflare Vite plugin

1y ago

Source

CloudflareWorkers - Enhanced support for static assets with the Cloudflare Vite plugincloudflare.com
Snippet from the RSS feed
You can now use any of Vite's static asset handling features in your Worker as well as in your frontend. These include importing assets as URLs, importing as strings and importing from the public directory as well as inlining assets. Additionally, assets imported as URLs in your Worker are now automatically moved to the client build output. Here is an example that fetches an imported asset using the assets binding and modifies the response. // Import the asset URL // This returns the resolved path in development and production import myImage from "./my-image.png" ; export default { async fetch ( request , env ) { // Fetch the asset using the binding const response = await env . ASSETS . fetch ( new URL ( myImage , request . url )) ; // Create a new `Response` object that can be modified const modifiedResponse = new Response ( response . body , response ) ; // Add an additional header modifiedResponse . headers . append ( "my-header" , "imported-asset" ) ; // Return the modified response return modifiedResponse ; }, }; Refer to Static Assets in the Cloudflare Vite plugin docs for more info.

You might also wanna read

Comments

Sign in to join the conversation.

No comments yet. Be the first.