|
| 1 | +--- |
| 2 | +title: Workers for Platforms now supports Static Assets |
| 3 | +description: ADD DESCRIPTION |
| 4 | +products: |
| 5 | + - workers-for-platforms |
| 6 | +date: 2025-01-31T01:00:00Z |
| 7 | +--- |
| 8 | + |
| 9 | +import { Render, TypeScriptExample } from "~/components"; |
| 10 | + |
| 11 | +Workers for Platforms customers can now attach static assets (HTML, CSS, JavaScript, images) directly to User Workers, removing the need to host separate infrastructure to serve the assets. |
| 12 | + |
| 13 | +This allows your platform to serve entire front-end applications from Cloudflare’s global edge, utilizing caching for fast load times, while supporting dynamic logic within the same Worker. Cloudflare automatically scales its infrastructure to handle high traffic volumes, enabling you to focus on building features without managing servers. |
| 14 | + |
| 15 | +## Use Cases |
| 16 | + |
| 17 | +### Static Sites |
| 18 | +Host and serve HTML, CSS, JavaScript, and media files directly from Cloudflare's network, ensuring fast loading times worldwide. This is ideal for blogs, landing pages, and documentation sites because static assets can be efficiently cached and delivered closer to the user, reducing latency and enhancing the overall user experience. |
| 19 | + |
| 20 | +### Full-Stack Applications |
| 21 | +Combine asset hosting with Cloudflare Workers to power dynamic, interactive applications. For example, an e-commerce platform can serve product pages while handling real-time inventory checks within the same Worker. |
| 22 | + |
| 23 | +<TypeScriptExample filename="index.ts"> |
| 24 | +```ts |
| 25 | +export default { |
| 26 | + async fetch(request, env) { |
| 27 | + const url = new URL(request.url); |
| 28 | + |
| 29 | + // Check real-time inventory |
| 30 | + if (url.pathname === '/api/inventory/check') { |
| 31 | + const product = url.searchParams.get('product'); |
| 32 | + const inventory = await env.INVENTORY_KV.get(product); |
| 33 | + return new Response(inventory); |
| 34 | + } |
| 35 | + |
| 36 | + // Serve static assets (HTML, CSS, images) |
| 37 | + return env.ASSETS.fetch(request); |
| 38 | + } |
| 39 | +}; |
| 40 | +``` |
| 41 | +</TypeScriptExample> |
| 42 | + |
| 43 | +You can upload static assets through the Workers for Platforms API or Wrangler. For more information, visit our [Workers for Platforms documentation](https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/configuration/static-assets/). |
0 commit comments