Compatibility Flags, Compatibility Date, and Runtime Behavior
How edge Worker compatibility flags and the compatibility date gate runtime behavior, Node.js APIs, fetch cache, and spec fixes—and how to opt in or out safely.
This page summarizes Cloudflare Workers documentation on compatibility flags: named switches that change how the Workers runtime behaves without you rewriting application code. Together with the compatibility date on a Worker, they control spec compliance fixes, Node.js compatibility modules, fetch and cache semantics, streams, WebSockets, and product-specific features such as Workflows and Containers.
Compatibility date: what turns on automatically
Section titled “Compatibility date: what turns on automatically”A Worker’s compatibility date is the primary control for which flags are on by default. When you set a compatibility date, every flag whose documented “default as of” date is on or before that date is enabled automatically unless you explicitly disable it.
When you set a compatibility date, all flags with an enable date on or before that date are automatically turned on.
— Cloudflare, How Workers interact with Cache Rules
Raising the compatibility date therefore opts you into newer, often breaking runtime behavior (URL parsing, fetch() cache modes, WebSocket binaryType, and similar). Keeping an older date preserves legacy behavior until you add flags manually or move the date forward.
Explicit enable and disable flags
Section titled “Explicit enable and disable flags”Each behavior change has a pair of names: one to enable the new behavior and one to revert to the old behavior. For example, spec-compliant URL handling uses url_standard to enable and url_original to disable (Compatibility flags).
Use an explicit disable flag when you need a newer compatibility date for some fixes but must keep one legacy behavior (for example retain_authorization_on_cross_origin_redirect if an API relies on sending Authorization after a cross-origin redirect).
How to set compatibility flags in Wrangler
Section titled “How to set compatibility flags in Wrangler”You configure the compatibility date and optional flag lists in Wrangler (for example compatibility_date and compatibility_flags in wrangler.toml or wrangler.jsonc). The Compatibility flags reference lists every flag, its enable/disable names, default dates, and prerequisites.
After you change the date or flags, redeploy the Worker and re-run the code paths that depend on the affected APIs—many differences only show up at runtime (caching, streams, error propagation, or Node.js module stubs).
Node.js compatibility (nodejs_compat) and roll-up flags
Section titled “Node.js compatibility (nodejs_compat) and roll-up flags”Many flags apply only when nodejs_compat is enabled. Several Node.js module stubs (for example node:http, node:fs, node:perf_hooks) are automatically enabled for Workers with a given compatibility date and nodejs_compat (Compatibility flags).
End-of-life API removal
Section titled “End-of-life API removal”When
remove_nodejs_compat_eolis enabled, APIs that have reached End-of-Life in Node.js will be removed for Workers.— Cloudflare, Compatibility flags
Version-specific roll-ups (such as remove_nodejs_compat_eol_v22, remove_nodejs_compat_eol_v23, remove_nodejs_compat_eol_v24) remove EOL APIs for particular Node.js lines as dates pass. Expect missing or non-functional stubs if you depend on deprecated Node APIs after enabling these flags.
process.env and require() behavior
Section titled “process.env and require() behavior”With nodejs_compat_populate_process_env, bindings (vars, secrets, metadata) can populate process.env, matching common Node patterns. The disallow_importable_env flag blocks both importable env via cloudflare:workers and auto-population on process.env when Node compat is on.
The require_returns_default_export flag changes whether require() returns the module namespace or the default export, which matters for frameworks such as Next.js that patch exports (Compatibility flags).
Fetch, cache, and Cache Rules
Section titled “Fetch, cache, and Cache Rules”Request cache option vs origin Cache-Control
Section titled “Request cache option vs origin Cache-Control”Workers gained standard cache: 'no-store' and cache: 'no-cache' on subrequests via cache_option_enabled and cache_no_cache_enabled. A separate fix, cache_option_preserves_cache_control, aligns Workers with the Fetch standard: the request cache mode controls how the cache uses a stored response, not how the response may be cached at the origin.
Per the Fetch standard, a request’s cache mode controls how the cache may use a stored response. It does not control how the response may be cached.
— Cloudflare, Compatibility flags
Without cache_option_preserves_cache_control, cache: 'no-cache' could effectively rewrite caching as if the origin had sent matching Cache-Control. With the flag enabled, to override origin cache policy you use cf.cacheControl on the fetch options instead of the cache property (Compatibility flags).
When Worker request.cf overrides Cache Rules
Section titled “When Worker request.cf overrides Cache Rules”Cache behavior in Workers also depends on flags that interact with Cache Rules on the zone:
| Flag | Enabled by default (compatibility date) | Notes |
|---|---|---|
request_cf_overrides_cache_rules |
On or after 2025-04-02 | Fetch API: request.cf cache settings take precedence over Cache Rules (Compatibility flags) |
cache_api_compat_flags |
On or after 2025-04-19 | Required for Cache API to honor compat flags (How Workers interact with Cache Rules) |
cache_api_request_cf_overrides_cache_rules |
On or after 2025-05-19 | Requires cache_api_compat_flags; Cache API override behavior |
Without it, the Cache API ignores all compatibility flags, even ones you explicitly list in your configuration.
— Cloudflare, How Workers interact with Cache Rules
If your compatibility date is before those thresholds, Cache Rules may win unless you add the flags manually—even when your Worker script sets cache options on fetch().
Cross-origin redirects and credentials
Section titled “Cross-origin redirects and credentials”strip_authorization_on_cross_origin_redirect removes the Authorization header when following a redirect to a different origin, as required by the current Fetch specification. Use retain_authorization_on_cross_origin_redirect only when you intentionally need the legacy behavior and accept credential-leak risk on untrusted redirect targets (Compatibility flags).
Web Platform spec compliance (streams, events, URLs)
Section titled “Web Platform spec compliance (streams, events, URLs)”Streams and pipeTo() error propagation
Section titled “Streams and pipeTo() error propagation”Flags such as pipe_to_backward_propagation, encoder_stream_spec_compliant_backpressure, and writable_stream_spec_compliant_writer align streams with the WHATWG Streams Standard. For example, with pipe_to_backward_propagation, errors and close events from the destination propagate back to the source as the spec requires; without it, the pipe might resolve instead of reject when the destination errors (Compatibility flags).
dispatchEvent() and listener exceptions
Section titled “dispatchEvent() and listener exceptions”spec_compliant_dispatch_exceptions makes runtime event dispatch match the DOM model: listener exceptions are reported but do not stop other listeners. Legacy service worker-style addEventListener("fetch", …) entry points are explicitly not affected and still propagate exceptions (Compatibility flags).
URL and URLPattern
Section titled “URL and URLPattern”url_standard replaces the original URL parser (slash collapsing, encoding, URL.canParse(), and related differences). urlpattern_standard provides a spec-compliant URLPattern implementation—a breaking change from the original; use urlpattern_original to revert if routing breaks after a date bump (Compatibility flags).
WebSockets, RPC, and product-specific flags
Section titled “WebSockets, RPC, and product-specific flags”WebSocket binaryType
Section titled “WebSocket binaryType”websocket_standard_binary_type defaults binaryType to "blob" (browser-like); legacy default is "arraybuffer". You can set binaryType per socket before accept(), or set no_websocket_standard_binary_type globally in Wrangler. Durable Object hibernatable webSocketMessage handlers always receive binary data as ArrayBuffer regardless (Compatibility flags).
Workers RPC stub lifetime
Section titled “Workers RPC stub lifetime”rpc_params_dup_stubs changes RPC so stubs in call parameters are duplicated rather than ownership-transferred, matching Cap’n Web semantics and fixing “RPC stub used after being disposed” in callback subscription patterns (Compatibility flags).
Workflows, Queues, Containers
Section titled “Workflows, Queues, Containers”- Workflows:
workflows_preserve_non_retryable_error_messagekeeps customNonRetryableErrormessages instead of a generic termination string;enable_validate_workflow_entrypointadds upload-time validation. - Queues:
queue_expose_error_codesadds structured error codes on queue operations. - Containers:
containers_pid_namespacegives the container an isolated PID namespace so the entrypoint is PID 1; without it, other VM processes may be visible over SSH (Compatibility flags, SSH).
Experimental and pedantic flags
Section titled “Experimental and pedantic flags”Some flags have no default enable date (for example pedantic_wpt, webcrypto_modern_algorithms, global_fetch_strictly_public). The docs group these under experimental behavior: opt in only when you need strict WPT compliance, modern crypto drafts, or public-internet routing for same-zone fetch().
pedantic_wpt currently focuses on Event / EventTarget but is intended to expand (Compatibility flags).
Common mistakes when changing flags or dates
Section titled “Common mistakes when changing flags or dates”- Bumping only the compatibility date without reading flag notes—fixes for
fetch()body iterables,URLSearchParams.deletewithforEach, or WebSocket defaults can break existing code silently until traffic hits the path. - Assuming
cache: 'no-cache'sets origin cache policy—untilcache_option_preserves_cache_controlis active for your date, or without usingcf.cacheControl, behavior may not match browser Fetch semantics. - Using Cache API with old dates without
cache_api_compat_flags—explicit compat flags in config are ignored for Cache API operations (How Workers interact with Cache Rules). - Enabling Node EOL removal while still calling deprecated APIs—prefer fixing call sites or pinning an older date with explicit
add_nodejs_compat_eol*disable flags until migration is done. - Subclassing Workers API objects on very old dates—
workers_api_getters_setters_on_prototype(default from 2022-01-31) fixes prototype getters/setters so subclasses can override behavior (Workers (Historic)).
How to check this on your site
Section titled “How to check this on your site”-
Note your Worker’s current
compatibility_dateandcompatibility_flagsin Wrangler, and compare them to the “default as of” dates for flags that affect your code paths in the Compatibility flags reference. -
If you use
fetch()caching, Cache API, orrequest.cfcache fields, cross-check against How Workers interact with Cache Rules and confirmcache_api_compat_flagsand related flags match your date. -
Deploy to a staging route (or use a Worker playground example with
playground: trueper the TypeScript example pattern) and exercise subrequests, streams, WebSockets, or Node imports your app relies on. -
After a date or flag change, monitor errors and queue/workflow messages for differences in error text, RPC stub disposal, or cache hit behavior.
-
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about, and we will correct or clarify it.