Skip to content

Commit 4239ae2

Browse files
[Static Assets] Rename experimental_serve_directly to run_worker_first (#19411)
Updates the naming for the Worker-first configuration.
1 parent ccf3183 commit 4239ae2

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

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

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

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

62-
## `experimental_serve_directly`
62+
## `run_worker_first`
6363

64-
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).
64+
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).
6565

6666
<WranglerConfig>
6767

@@ -74,7 +74,7 @@ main = "src/index.ts"
7474
[assets]
7575
directory = "./public/"
7676
binding = "ASSETS"
77-
experimental_serve_directly = false
77+
run_worker_first = true
7878
```
7979

8080
</WranglerConfig>
@@ -166,16 +166,16 @@ For the various static asset routing configuration options, refer to [Routing](/
166166

167167
### Smart Placement with Worker Code First
168168

169-
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.
169+
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.
170170

171-
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.
171+
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.
172172

173173
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).
174174

175175
### Smart Placement with Assets First
176176

177-
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).
177+
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).
178178

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

181181
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/) |||
@@ -90,7 +90,7 @@ We plan to bridge the gaps between Workers and Pages and provide ways to migrate
9090

9191
[^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.
9292

93-
[^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.
93+
[^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.
9494

9595
[^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/).
9696

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
Render,
1616
TabItem,
1717
Tabs,
18-
WranglerConfig
18+
WranglerConfig,
1919
} from "~/components";
2020

2121
## Default behavior
@@ -38,7 +38,7 @@ In this example, a request to `example.com/api` doesn't match a static asset so
3838

3939
## Invoking Worker Script Ahead of Assets
4040

41-
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 the `wrangler.toml / wrangler.json` file 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.
41+
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 / wrangler.json` 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.
4242

4343
Take the following directory structure, `wrangler.toml / wrangler.json` file, and user Worker code:
4444

@@ -59,7 +59,7 @@ Take the following directory structure, `wrangler.toml / wrangler.json` file, an
5959
name = "my-worker"
6060
compatibility_date = "2024-09-19"
6161
main = "src/index.ts"
62-
assets = { directory = "./public/", binding = "ASSETS", experimental_serve_directly = false }
62+
assets = { directory = "./public/", binding = "ASSETS", run_worker_first = true }
6363
```
6464

6565
</WranglerConfig>
@@ -90,7 +90,7 @@ export default {
9090
};
9191
```
9292

93-
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.
93+
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.
9494

9595
## Routing configuration
9696

@@ -321,3 +321,4 @@ In this example, requests to `example.com/blog/` will serve the `index.html` fil
321321

322322
If you have a file outside the configured path, it will not be served. For example, if you have a `home.html` file in the root of your asset directory, it will not be served when requesting `example.com/blog/home`.
323323
However, if needed, these files can still be manually fetched over [the binding](/workers/static-assets/binding/#binding).
324+
```

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

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

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

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

989-
- 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).
989+
- 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).
990990

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

0 commit comments

Comments
 (0)