You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/cloudflare-for-platforms/workers-for-platforms/configuration/static-assets.mdx
+17-14Lines changed: 17 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
pcx_content_type: concept
3
-
title: Static Assets
3
+
title: Static assets
4
4
---
5
5
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.
6
6
@@ -25,11 +25,11 @@ Deploy front-end assets alongside server-side logic, all within Cloudflare Worke
25
25
26
26
---
27
27
28
-
## Deploying static assets to User Workers
28
+
## Deploy static assets to User Workers
29
29
30
-
It's common that as the Platform, you will be responsible for uploading static assets on behalf of your end users. This often looks like this:
30
+
It is common that, as the Platform, you will be responsible for uploading static assets on behalf of your end users. This often looks like this:
31
31
32
-
1.User uploads files (HTML, CSS, images) through your interface.
32
+
1.Your user uploads files (HTML, CSS, images) through your interface.
33
33
2. Your platform interacts with the Workers for Platforms APIs to attach the static assets to the User Worker script.
34
34
35
35
Once you receive the static files from your users (for a new or updated site), complete the following steps to attach the files to the corresponding User Worker:
@@ -38,7 +38,7 @@ Once you receive the static files from your users (for a new or updated site), c
38
38
2. Upload file contents
39
39
3. Deploy/Update the Worker
40
40
41
-
After these steps are completed, the User Worker's static assets will be live on Cloudflare's edge.
41
+
After these steps are completed, the User Worker's static assets will be live on the Cloudflare's global network.
42
42
43
43
### 1. Create an Upload Session
44
44
@@ -63,7 +63,7 @@ Before sending any file data, you need to tell Cloudflare which files you intend
63
63
}
64
64
```
65
65
66
-
To start the upload process, send a POST request to the Create Assets Upload Session [API endpoint](/api/resources/workers_for_platforms/subresources/dispatch/subresources/namespaces/subresources/scripts/subresources/asset_upload/methods/create/)
66
+
To start the upload process, send a POST request to the Create Assets Upload Session [API endpoint](/api/resources/workers_for_platforms/subresources/dispatch/subresources/namespaces/subresources/scripts/subresources/asset_upload/methods/create/).
67
67
68
68
```bash
69
69
POST /accounts/{account_id}/workers/dispatch/namespaces/{namespace}/scripts/{script_name}/assets-upload-session
@@ -103,10 +103,13 @@ You can compute a SHA-256 digest of the file contents, then truncate or otherwis
103
103
**API Response**
104
104
105
105
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:
106
-
*`jwt`: An upload token (valid for 1 hour) which will be used in the API request to upload the file contents (Step 2)
106
+
107
+
*`jwt`: An upload token (valid for 1 hour) which will be used in the API request to upload the file contents (Step 2).
107
108
*`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.
108
109
109
-
**Note**: This step alone does not store files on Cloudflare. You must upload the actual file data in the next step.
110
+
:::note
111
+
This step alone does not store files on Cloudflare. You must upload the actual file data in the next step.
112
+
:::
110
113
111
114
### 2. Upload File Contents
112
115
@@ -129,7 +132,7 @@ This token is valid for one hour and must be supplied for each upload request to
129
132
**File fields (multipart/form-data)**
130
133
You must send the files as multipart/form-data with base64-encoded content:
131
134
132
-
* Field name: The file hash (for example, "36b8be012ee77df5f269b11b975611d3")
135
+
* Field name: The file hash (for example, `36b8be012ee77df5f269b11b975611d3`)
133
136
* Field value: A Base64-encoded string of the file's raw bytes
134
137
135
138
**Example: Uploading multiple files within a single bucket**
@@ -161,7 +164,7 @@ curl -X POST \
161
164
162
165
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.
163
166
164
-
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.
167
+
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.
165
168
166
169
```json
167
170
{
@@ -176,11 +179,11 @@ Once every file in the manifest has been uploaded, a status code of 201 will be
176
179
177
180
`<completion-token>` indicates that Cloudflare has successfully received and stored the file contents specified by your manifest. You will use this `<completion-token>` in Step 3 to finalize the attachment of these files to the Worker.
178
181
179
-
### 3. Deploy the User Worker with Static Assets
182
+
### 3. Deploy the User Worker with static assets
180
183
181
184
Now that Cloudflare has all the files it needs (from the previous upload steps), you must attach them to the User Worker by making a PUT request to the [Upload User Worker API](https://developers.cloudflare.com/api/resources/workers_for_platforms/subresources/dispatch/subresources/namespaces/subresources/scripts/methods/update/). This final step links the static assets to the User Worker using the completion token you received after uploading file contents.
182
185
183
-
You can also specify any optional settings under the assets.config field to customize how your files are served (for example, to handle trailing slashes in HTML paths).
186
+
You can also specify any optional settings under the `assets.config` field to customize how your files are served (for example, to handle trailing slashes in HTML paths).
184
187
185
188
**API request example:**
186
189
@@ -204,7 +207,7 @@ curl -X PUT \
204
207
205
208
* The `"jwt": "<completion-token>"` links the newly uploaded files to the Worker
206
209
* Including "html_handling" (or other fields under "config") is optional and can customize how static files are served
207
-
* If the user's Worker code hasn't changed, you can omit the code file or re-upload the same index.js
210
+
* If the user's Worker code has not changed, you can omit the code file or re-upload the same index.js
208
211
209
212
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.
210
213
@@ -242,7 +245,7 @@ export default {
242
245
},
243
246
};
244
247
```
245
-
### 2. Deploy the User Worker with the Static Assets
248
+
### 2. Deploy the User Worker with the static assets
246
249
247
250
Run Wrangler to publish both your Worker code and the static assets:
0 commit comments