How Snippets work
Last updated Oct 16, 2026 Cloudflare Snippets are executed based on rules defined within your zone. Here is how the process works:

1. Evaluate snippet rules
For each incoming request, Cloudflare evaluates the expression of every snippet rule defined in the zone. The evaluation checks for a match based on various request properties (such as bot score, WAF attack score, country of origin, and cookies).
2. Build Snippets table
For every snippet rule in a zone that matches an incoming request, Cloudflare adds the corresponding unique snippet ID to a Snippets table.
3. Execute snippets code
Once all the rules have been evaluated and the full table has been compiled, Cloudflare starts processing all the snippet IDs in the table.
The snippets are executed sequentially. Each snippet receives the modified request from the previous snippet and applies new modifications to it.
4. Continue with the request execution workflow
After executing the final snippet IDs, the resulting modified request is passed back to the request execution workflow. Refer to Execution order for more information on the Rules features evaluated before and after Cloudflare Snippets.
Subrequests made by a snippet
When a snippet calls fetch() to a proxied hostname in the same zone, the request that the snippet makes is a subrequest. The incoming request that triggered the snippet is evaluated as normal, including by the security features configured for the hostname the visitor requested.
WAF custom rules and WAF managed rules on the target hostname are not evaluated for a same-zone subrequest made by a snippet. This applies to both fetch(url) and fetch(request).
Caution
Do not rely on custom rules on the target hostname to restrict access to subrequests made by a snippet. To protect the target, apply protections to the incoming request that triggers the snippet, or validate the request at the target itself (for example, in your origin server or in a Worker).
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/rules/snippets/how-it-works/#page","headline":"How Snippets work","description":"How Snippets execute JavaScript at the edge for matching requests.","url":"https://developers.cloudflare.com/rules/snippets/how-it-works/","inLanguage":"en","image":"https://developers.cloudflare.com/rules/snippets/how-it-works/og.png?v=f018bf2c62451e77","dateModified":"2026-10-16","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: This guide helps you determine when to use Snippets or Workers on Cloudflare's global network. title: When to use Snippets vs Workers image: https://developers.cloudflare.com/rules/snippets/when-to-use/og.png?v=c051752b2216150f
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/rules/llms.txt
Use this file to discover all available pages before exploring further.
