Skip to content

Commit 28109fd

Browse files
committed
Adds warning under Create an Upload Session
1 parent 52edd5f commit 28109fd

File tree

1 file changed

+54
-35
lines changed
  • src/content/docs/cloudflare-for-platforms/workers-for-platforms/configuration

1 file changed

+54
-35
lines changed

src/content/docs/cloudflare-for-platforms/workers-for-platforms/configuration/static-assets.mdx

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,33 @@ pcx_content_type: concept
33
title: Static assets
44
description: Host static assets on Cloudflare's global network and deliver faster load times worldwide with Workers for Platforms.
55
---
6+
7+
import { Aside } from "@astrojs/starlight/components";
8+
69
Workers for Platforms lets you deploy front-end applications at scale. By hosting static assets on Cloudflare's global network, you can deliver faster load times worldwide and eliminate the need for external infrastructure. You can also combine these static assets with dynamic logic in Cloudflare Workers, providing a full-stack experience for your customers.
710

811
### What you can build
912

1013
#### Static sites
14+
1115
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.
1216

1317
#### Full-stack applications
18+
1419
Combine asset hosting with Cloudflare Workers to power dynamic, interactive applications. Store and retrieve data using Cloudflare KV, D1, and R2 Storage, allowing you to serve both front-end assets and backend logic from a single Worker.
1520

1621
### Benefits
1722

1823
#### Global caching for faster performance
24+
1925
Cloudflare automatically caches static assets at data centers worldwide, reducing latency and improving load times by up to 2x for users everywhere.
2026

2127
#### Scalability without infrastructure management
28+
2229
Your applications scale automatically to handle high traffic without requiring you to provision or manage infrastructure. Cloudflare dynamically adjusts to demand in real time.
2330

2431
#### Unified deployment for static and dynamic content
32+
2533
Deploy front-end assets alongside server-side logic, all within Cloudflare Workers. This eliminates the need for a separate hosting provider and ensures a streamlined deployment process.
2634

2735
---
@@ -45,22 +53,30 @@ After these steps are completed, the User Worker's static assets will be live on
4553

4654
Before sending any file data, you need to tell Cloudflare which files you intend to upload. That list of files is called a manifest. Each item in the manifest includes:
4755

48-
* A file path (for example, `"/index.html"` or `"/assets/logo.png"`)
49-
* A hash (32-hex characters) representing the file contents
50-
* The file size in bytes
56+
- A file path (for example, `"/index.html"` or `"/assets/logo.png"`)
57+
- A hash (32-hex characters) representing the file contents
58+
- The file size in bytes
59+
60+
<Aside type="caution" title="About asset isolation">
61+
Cloudflare automatically de-duplicates identical asset hashes within the same
62+
account. If an asset with the same hash has already been uploaded, it may be
63+
shared across different User Workers **unless explicitly made unique**. If you
64+
require full asset isolation, prepend asset hashes with a unique identifier
65+
(for example, an account ID or Worker name).
66+
</Aside>
5167

5268
#### Example manifest (JSON)
5369

5470
```json
5571
{
56-
"/index.html": {
57-
"hash": "08f1dfda4574284ab3c21666d1ee8c7d4",
58-
"size": 1234
59-
},
60-
"/styles.css": {
61-
"hash": "36b8be012ee77df5f269b11b975611d3",
62-
"size": 5678
63-
}
72+
"/index.html": {
73+
"hash": "08f1dfda4574284ab3c21666d1ee8c7d4",
74+
"size": 1234
75+
},
76+
"/styles.css": {
77+
"hash": "36b8be012ee77df5f269b11b975611d3",
78+
"size": 5678
79+
}
6480
}
6581
```
6682

@@ -71,8 +87,9 @@ POST /accounts/{account_id}/workers/dispatch/namespaces/{namespace}/scripts/{scr
7187
```
7288

7389
Path Parameters:
74-
* `namespace`: Name of the Workers for Platforms dispatch namespace
75-
* `script_name`: Name of the User Worker
90+
91+
- `namespace`: Name of the Workers for Platforms dispatch namespace
92+
- `script_name`: Name of the User Worker
7693

7794
In the request body, include a JSON object listing each file path along with its hash and size. This helps Cloudflare identify which files you intend to upload and allows Cloudflare to check if any of them are already stored.
7895

@@ -105,8 +122,8 @@ You can compute a SHA-256 digest of the file contents, then truncate or otherwis
105122

106123
If all the files are already stored on Cloudflare, the response will only return the JWT token. If new or updated files are needed, the response will return:
107124

108-
* `jwt`: An upload token (valid for 1 hour) which will be used in the API request to upload the file contents (Step 2).
109-
* `buckets`: An array of file-hash groups indicating which files to upload together. Files that have been recently uploaded won't appear in buckets, since Cloudflare already has them.
125+
- `jwt`: An upload token (valid for 1 hour) which will be used in the API request to upload the file contents (Step 2).
126+
- `buckets`: An array of file-hash groups indicating which files to upload together. Files that have been recently uploaded won't appear in buckets, since Cloudflare already has them.
110127

111128
:::note
112129
This step alone does not store files on Cloudflare. You must upload the actual file data in the next step.
@@ -131,10 +148,11 @@ Authorization: Bearer <upload-session-token>
131148
This token is valid for one hour and must be supplied for each upload request to the Workers Assets Upload API.
132149

133150
#### File fields (multipart/form-data)
151+
134152
You must send the files as multipart/form-data with base64-encoded content:
135153

136-
* Field name: The file hash (for example, `36b8be012ee77df5f269b11b975611d3`)
137-
* Field value: A Base64-encoded string of the file's raw bytes
154+
- Field name: The file hash (for example, `36b8be012ee77df5f269b11b975611d3`)
155+
- Field value: A Base64-encoded string of the file's raw bytes
138156

139157
#### Example: Uploading multiple files within a single bucket
140158

@@ -159,22 +177,22 @@ curl -X POST \
159177
-F "36b8be012ee77df5f269b11b975611d3=<BASE64_OF_STYLES_CSS>"
160178
```
161179

162-
* `<upload-session-token>` is the token from step 1's assets-upload-session response
163-
* `<BASE64_OF_INDEX_HTML>` is the Base64-encoded content of index.html
164-
* `<BASE64_OF_STYLES_CSS>` is the Base64-encoded content of styles.css
180+
- `<upload-session-token>` is the token from step 1's assets-upload-session response
181+
- `<BASE64_OF_INDEX_HTML>` is the Base64-encoded content of index.html
182+
- `<BASE64_OF_STYLES_CSS>` is the Base64-encoded content of styles.css
165183

166184
If you have multiple buckets (for example, `[["hashA"], ["hashB"], ["hashC"]]`), you might need to repeat this process for each bucket, making one request per bucket group.
167185

168186
Once every file in the manifest has been uploaded, a status code of `201` will be returned, with the `jwt` field present. This JWT is a final "completion" token which can be used to create a deployment of a Worker with this set of assets. This completion token is valid for 1 hour.
169187

170188
```json
171189
{
172-
"success": true,
173-
"errors": [],
174-
"messages": [],
175-
"result": {
176-
"jwt": "<completion-token>"
177-
}
190+
"success": true,
191+
"errors": [],
192+
"messages": [],
193+
"result": {
194+
"jwt": "<completion-token>"
195+
}
178196
}
179197
```
180198

@@ -206,9 +224,9 @@ curl -X PUT \
206224
-F 'index.js=@/path/to/index.js;type=application/javascript'
207225
```
208226

209-
* The `"jwt": "<completion-token>"` links the newly uploaded files to the Worker
210-
* Including "html_handling" (or other fields under "config") is optional and can customize how static files are served
211-
* If the user's Worker code has not changed, you can omit the code file or re-upload the same index.js
227+
- The `"jwt": "<completion-token>"` links the newly uploaded files to the Worker
228+
- Including "html_handling" (or other fields under "config") is optional and can customize how static files are served
229+
- If the user's Worker code has not changed, you can omit the code file or re-upload the same index.js
212230

213231
Once this PUT request succeeds, the files are served on the User Worker. Requests routed to that Worker will serve the new or updated static assets.
214232

@@ -236,8 +254,8 @@ binding = "ASSETS"
236254

237255
</WranglerConfig>
238256

239-
* `directory`: The local folder containing your static files (for example, `./public`).
240-
* `binding`: The binding name used to reference these assets within your Worker code.
257+
- `directory`: The local folder containing your static files (for example, `./public`).
258+
- `binding`: The binding name used to reference these assets within your Worker code.
241259

242260
### 1. Organize your files
243261

@@ -247,11 +265,12 @@ If you need to reference these files in your Worker script to serve them dynamic
247265

248266
```js
249267
export default {
250-
async fetch(request, env, ctx) {
251-
return env.ASSETS.fetch(request);
252-
},
268+
async fetch(request, env, ctx) {
269+
return env.ASSETS.fetch(request);
270+
},
253271
};
254272
```
273+
255274
### 2. Deploy the User Worker with the static assets
256275

257276
Run Wrangler to publish both your Worker code and the static assets:
@@ -260,4 +279,4 @@ Run Wrangler to publish both your Worker code and the static assets:
260279
npx wrangler deploy --name <USER_WORKER_NAME> --dispatch-namespace <NAMESPACE_NAME>
261280
```
262281

263-
Wrangler will automatically detect your static files, bundle them, and upload them to Cloudflare along with your Worker code.
282+
Wrangler will automatically detect your static files, bundle them, and upload them to Cloudflare along with your Worker code.

0 commit comments

Comments
 (0)