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
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.
7
10
8
11
### What you can build
9
12
10
13
#### Static sites
14
+
11
15
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.
12
16
13
17
#### Full-stack applications
18
+
14
19
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.
15
20
16
21
### Benefits
17
22
18
23
#### Global caching for faster performance
24
+
19
25
Cloudflare automatically caches static assets at data centers worldwide, reducing latency and improving load times by up to 2x for users everywhere.
20
26
21
27
#### Scalability without infrastructure management
28
+
22
29
Your applications scale automatically to handle high traffic without requiring you to provision or manage infrastructure. Cloudflare dynamically adjusts to demand in real time.
23
30
24
31
#### Unified deployment for static and dynamic content
32
+
25
33
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.
26
34
27
35
---
@@ -45,22 +53,29 @@ After these steps are completed, the User Worker's static assets will be live on
45
53
46
54
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:
47
55
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
Static assets uploaded to Workers for Platforms are associated with the namespace rather than with individual User Worker. If multiple User Workers exist under the same namespace, assets with identical hashes may be shared across them. **JWTs should therefore only be shared with trusted platform services and should never be distributed to end-users.**
62
+
63
+
If strict isolation of assets is required, we recommend either salting with a random value each time, or incorporating an end-user identifier (e.g. account ID or Worker script ID) within the hashing process, to ensure uniqueness. For example, `hash = slice(sha256(accountID + fileContents), 32)`.
64
+
65
+
</Aside>
51
66
52
67
#### Example manifest (JSON)
53
68
54
69
```json
55
70
{
56
-
"/index.html": {
57
-
"hash": "08f1dfda4574284ab3c21666d1ee8c7d4",
58
-
"size": 1234
59
-
},
60
-
"/styles.css": {
61
-
"hash": "36b8be012ee77df5f269b11b975611d3",
62
-
"size": 5678
63
-
}
71
+
"/index.html": {
72
+
"hash": "08f1dfda4574284ab3c21666d1ee8c7d4",
73
+
"size": 1234
74
+
},
75
+
"/styles.css": {
76
+
"hash": "36b8be012ee77df5f269b11b975611d3",
77
+
"size": 5678
78
+
}
64
79
}
65
80
```
66
81
@@ -71,8 +86,9 @@ POST /accounts/{account_id}/workers/dispatch/namespaces/{namespace}/scripts/{scr
71
86
```
72
87
73
88
Path Parameters:
74
-
*`namespace`: Name of the Workers for Platforms dispatch namespace
75
-
*`script_name`: Name of the User Worker
89
+
90
+
-`namespace`: Name of the Workers for Platforms dispatch namespace
91
+
-`script_name`: Name of the User Worker
76
92
77
93
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.
78
94
@@ -105,8 +121,8 @@ You can compute a SHA-256 digest of the file contents, then truncate or otherwis
105
121
106
122
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:
107
123
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.
124
+
-`jwt`: An upload token (valid for 1 hour) which will be used in the API request to upload the file contents (Step 2).
125
+
-`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.
110
126
111
127
:::note
112
128
This step alone does not store files on Cloudflare. You must upload the actual file data in the next step.
@@ -118,6 +134,10 @@ If the response to the Upload Session API returns `buckets`, that means you have
118
134
119
135
Use the [Workers Assets Upload API](https://developers.cloudflare.com/api/resources/workers/subresources/assets/subresources/upload/) to transmit the raw file bytes in base64-encoded format for any missing or changed files. Once uploaded, Cloudflare will store these files so they can then be attached to a User Worker.
120
136
137
+
<Asidetype="caution">
138
+
Asset uniqueness is determined by the provided hash and are associated globally to their namespace rather than with each specific User Worker. If an asset has already been uploaded for that namespace earlier, Cloudflare will automatically omit sending this asset hash back in the `buckets` response to save you from re-uploading the same thing twice. This means that an asset can be shared between multiple User Workers if it shares the same hash unless you **explicitly make the hash unique**. If you require full isolation between assets across User Workers, incorporate a unique identifier within your asset hashing process (either salting it with something entirely random each time, or by including the end-user account ID or their Worker name to retain per-customer re-use).
139
+
</Aside>
140
+
121
141
#### API Request Authentication
122
142
123
143
Unlike most Cloudflare API calls that use an account-wide API token in the Authorization header, uploading file contents requires using the short-lived JWT token returned in the `jwt` field of the `assets-upload-session` response.
*`<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
183
+
-`<upload-session-token>` is the token from step 1's assets-upload-session response
184
+
-`<BASE64_OF_INDEX_HTML>` is the Base64-encoded content of index.html
185
+
-`<BASE64_OF_STYLES_CSS>` is the Base64-encoded content of styles.css
165
186
166
187
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.
167
188
168
189
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.
0 commit comments