Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/content/docs/en/guides/integrations-guide/cloudflare.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ It also accepts the following:
### `imageService`

<p>
**Type:** `'passthrough' | 'cloudflare' | 'cloudflare-binding' | 'compile' | 'custom' | { build: 'compile', runtime?: 'cloudflare-binding' | 'passthrough' }`<br />
**Type:** `'passthrough' | 'cloudflare' | 'cloudflare-binding' | 'compile' | 'custom' | { build: 'compile', runtime?: 'cloudflare-binding' | 'passthrough' } | { build: 'cloudflare-binding', runtime?: 'cloudflare-binding' | 'passthrough' }`<br />
Comment thread
alexanderniebuhr marked this conversation as resolved.
Outdated
**Default:** `'cloudflare-binding'`
</p>

Expand All @@ -128,7 +128,11 @@ Determines which image service is used by the adapter. The adapter will default
- **`compile`:** Uses the [configured image service](/en/reference/configuration-reference/#imageservice) or falls back to a combination of internal dependencies to transform images locally at build time for prerendered routes. The noop `passthrough` option is configured for on-demand rendered pages.
- **`custom`:** Uses the [configured image service](/en/reference/configuration-reference/#imageservice) (defaults to Sharp) to process assets at build time for prerendered routes. Bundles the image service for runtime image handling, without checking its compatibility with Cloudflare's `workerd` runtime.

It is also possible to configure your image service as an object, setting both a build time and runtime service independently. Currently, `'compile'` is the only available build-time option. The supported runtime options are `'passthrough'` (default) and `'cloudflare-binding'`:
<p><Since v="14.2.0" pkg="@astrojs/cloudflare" /></p>

You can also configure the image service as an object by providing a build-time service (`compile` or `cloudflare-binding`) and, optionally, a runtime service (`passthrough` or `cloudflare-binding`).

When the runtime service is omitted, its default value depends on the configured build-time service. It falls back to `'passthrough'` for `build: 'compile'` and to `'cloudflare-binding'` for `build: 'cloudflare-binding'`.

```js title="astro.config.mjs" ins={6}
import { defineConfig } from 'astro/config';
Expand All @@ -141,6 +145,21 @@ export default defineConfig({
});
```

Using `imageService: 'cloudflare-binding'` enables image optimization using the [Cloudflare Images binding](https://developers.cloudflare.com/images/transform-images/bindings/) only at runtime.

To opt in to build-time image optimization with the binding during `workerd` prerendering, set `build` to `'cloudflare-binding'`. If the binding fails to transform an image at build time, the adapter falls back to the [configured image service](/en/reference/configuration-reference/#imageservice) (defaults to Sharp).

```js title="astro.config.mjs" ins={6}
import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';

export default defineConfig({
adapter: cloudflare({
imageService: { build: 'cloudflare-binding', runtime: 'cloudflare-binding' }
Comment thread
alexanderniebuhr marked this conversation as resolved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed we still show build and runtime here. Have you changed your mind about removing runtime? It's not a problem if that's the case, I just want to make sure it wasn't marked as resolved by mistake.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think even if it is the default value, we should still be able to configure it. Maybe the code PR needs an update here.

}),
});
```

### `sessionKVBindingName`

<p>
Expand Down
Loading