Skip to content

Commit aa6bedf

Browse files
committed
[Static Assets] Rename experimental_serve_directly to run_worker_first
Updates the naming for the Worker-first configuration.
1 parent bc92e8a commit aa6bedf

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

public/_redirects

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,8 @@
18981898
/workers/reference/apis/* /workers/runtime-apis/:splat 301
18991899
/workers/templates/pages/* /workers/examples/:splat 301
19001900
/workers/observability/logging/* /workers/observability/logs/:splat 301
1901+
/workers/observability/logging/* /workers/observability/logs/:splat 301
1902+
/workers/static-assets/binding/#experimental_serve_directly /workers/static-assets/binding/#run_worker_first 301
19011903

19021904
# Others
19031905
/ssl/custom-certificates/* /ssl/edge-certificates/custom-certificates/:splat 301

src/content/docs/workers/static-assets/binding.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ _headers
6060

6161
Now Wrangler will not upload these files as client-side assets when deploying the Worker.
6262

63-
## `experimental_serve_directly`
63+
## `run_worker_first`
6464

65-
Controls whether assets will be served first on a matching request. `experimental_serve_directly = true` ([default](/workers/static-assets/routing/#default-behavior)) will serve any static asset matching a request, while `experimental_serve_directly = false` will unconditionally [invoke your Worker script](/workers/static-assets/routing/#invoking-worker-script-ahead-of-assets).
65+
Controls whether to invoke the Worker script regardless of a request which would have otherwise matched an asset. `run_worker_first = false` ([default](/workers/static-assets/routing/#default-behavior)) will serve any static asset matching a request, while `run_worker_first = true` will unconditionally [invoke your Worker script](/workers/static-assets/routing/#invoking-worker-script-ahead-of-assets).
6666

6767
<WranglerConfig>
6868

@@ -75,7 +75,7 @@ main = "src/index.ts"
7575
[assets]
7676
directory = "./public/"
7777
binding = "ASSETS"
78-
experimental_serve_directly = false
78+
run_worker_first = true
7979
```
8080

8181
</WranglerConfig>
@@ -167,16 +167,16 @@ For the various static asset routing configuration options, refer to [Routing](/
167167

168168
### Smart Placement with Worker Code First
169169

170-
If you desire to run your [Worker code ahead of assets](/workers/static-assets/routing/#invoking-worker-script-ahead-of-assets) by setting `experimental_serve_directly=false`, all requests must first travel to your Smart-Placed Worker. As a result, you may experience increased latency for asset requests.
170+
If you desire to run your [Worker code ahead of assets](/workers/static-assets/routing/#invoking-worker-script-ahead-of-assets) by setting `run_worker_first=true`, all requests must first travel to your Smart-Placed Worker. As a result, you may experience increased latency for asset requests.
171171

172-
Use Smart Placement with `experimental_serve_directly=false` when you need to integrate with other backend services, authenticate requests before serving any assets, or if your want to make modifications to your assets before serving them.
172+
Use Smart Placement with `run_worker_first=true` when you need to integrate with other backend services, authenticate requests before serving any assets, or if your want to make modifications to your assets before serving them.
173173

174174
If you want some assets served as quickly as possible to the user, but others to be served behind a smart-placed Worker, considering splitting your app into multiple Workers and [using service bindings to connect them](/workers/configuration/smart-placement/#best-practices).
175175

176176
### Smart Placement with Assets First
177177

178-
Enabling Smart Placement with `experimental_serve_directly=true` lets you serve assets from as close as possible to your users, but moves your Worker logic to run most efficiently (such as near a database).
178+
Enabling Smart Placement with `run_worker_first=false` (or not specifying it) lets you serve assets from as close as possible to your users, but moves your Worker logic to run most efficiently (such as near a database).
179179

180-
Use Smart Placement with `experimental_serve_directly=true` when prioritizing fast asset delivery.
180+
Use Smart Placement with `run_worker_first=false` (or not specifying it) when prioritizing fast asset delivery.
181181

182182
This will not impact the [default routing behavior](/workers/static-assets/routing/#default-behavior).

src/content/docs/workers/static-assets/compatibility-matrix.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ We plan to bridge the gaps between Workers and Pages and provide ways to migrate
4040
| **Static Assets** | | |
4141
| [Early Hints](/pages/configuration/early-hints/) |||
4242
| [Custom HTTP headers for static assets](/pages/configuration/headers/) | 🟡 [^1] ||
43-
| [Middleware](/workers/static-assets/binding/#experimental_serve_directly) |[^2] ||
43+
| [Middleware](/workers/static-assets/binding/#run_worker_first) |[^2] ||
4444
| [Redirects](/pages/configuration/redirects/) | 🟡 [^3] ||
4545
| [Smart Placement](/workers/configuration/smart-placement/) |||
4646
| [Serve assets on a path](/workers/static-assets/routing/) |||
@@ -85,7 +85,7 @@ We plan to bridge the gaps between Workers and Pages and provide ways to migrate
8585

8686
[^1]: Similar to <sup>3</sup>, to customize the HTTP headers that are returned by static assets, you can use [Service bindings](/workers/runtime-apis/bindings/service-bindings/) to connect a Worker in front of the Worker with assets.
8787

88-
[^2]: Middleware can be configured via the [`experimental_serve_directly`](/workers/static-assets/binding/#experimental_serve_directly) option, but is charged as a normal Worker invocation. We plan to explore additional related options in the future.
88+
[^2]: Middleware can be configured via the [`run_worker_first`](/workers/static-assets/binding/#run_worker_first) option, but is charged as a normal Worker invocation. We plan to explore additional related options in the future.
8989

9090
[^3]: You can handle redirects by adding code to your Worker (a [community package](https://npmjs.com/package/redirects-in-workers) is available for `_redirects` support), or you can use [Bulk Redirects](/rules/url-forwarding/bulk-redirects/).
9191

src/content/docs/workers/static-assets/routing.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ In this example, a request to `example.com/api` doesn't match a static asset so
3939

4040
## Invoking Worker Script Ahead of Assets
4141

42-
You may wish to run code before assets are served. This is often the case when implementing authentication, logging, personalization, internationalization, or other similar functions. [`experimental_serve_directly`](/workers/static-assets/binding/#experimental_serve_directly) is a configuration option available in `wrangler.toml` which controls this behavior. When disabled, `experimental_serve_directly = false` will invoke your Worker's code, regardless of any assets that would have otherwise matched.
42+
You may wish to run code before assets are served. This is often the case when implementing authentication, logging, personalization, internationalization, or other similar functions. [`run_worker_first`](/workers/static-assets/binding/#run_worker_first) is a configuration option available in `wrangler.toml` which controls this behavior. When enabled, `run_worker_first = true` will invoke your Worker's code, regardless of any assets that would have otherwise matched.
4343

4444
Take the following directory structure, wrangler.toml, and user Worker code:
4545

@@ -60,7 +60,7 @@ Take the following directory structure, wrangler.toml, and user Worker code:
6060
name = "my-worker"
6161
compatibility_date = "2024-09-19"
6262
main = "src/index.ts"
63-
assets = { directory = "./public/", binding = "ASSETS", experimental_serve_directly = false }
63+
assets = { directory = "./public/", binding = "ASSETS", run_worker_first = true }
6464
```
6565

6666
</WranglerConfig>
@@ -91,7 +91,7 @@ export default {
9191
};
9292
```
9393

94-
In this example, any request will be routed to our user Worker, due to `experimental_serve_directly` being disabled. As a result, any request being made `/supersecret.txt` without an `Authorization` header will result in a 403.
94+
In this example, any request will be routed to our user Worker, due to `run_worker_first` being enabled. As a result, any request being made `/supersecret.txt` without an `Authorization` header will result in a 403.
9595

9696
## Routing configuration
9797

src/content/docs/workers/wrangler/configuration.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,9 +986,9 @@ The following options are available under the `assets` key.
986986

987987
- The binding name used to refer to the assets. Optional, and only useful when a Worker script is set with `main`.
988988

989-
- `experimental_serve_directly` <Type text="boolean" /> <MetaInfo text="optional, defaults to true" />
989+
- `run_worker_first` <Type text="boolean" /> <MetaInfo text="optional, defaults to false" />
990990

991-
- Controls whether static assets are fetched directly, or a Worker script is invoked. Learn more about fetching assets when using [`experimental_serve_directly`](/workers/static-assets/routing/#invoking-worker-script-ahead-of-assets).
991+
- Controls whether static assets are fetched directly, or a Worker script is invoked. Learn more about fetching assets when using [`run_worker_first`](/workers/static-assets/routing/#invoking-worker-script-ahead-of-assets).
992992

993993
- `html_handling`: <Type text={'"auto-trailing-slash" | "force-trailing-slash" | "drop-trailing-slash" | "none"'} /> <MetaInfo text={'optional, defaults to "auto-trailing-slash"'} />
994994

0 commit comments

Comments
 (0)