
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
    <channel>
        <title><![CDATA[ The Cloudflare Blog ]]></title>
        <description><![CDATA[ Get the latest news on how products at Cloudflare are built, technologies used, and join the teams helping to build a better Internet. ]]></description>
        <link>https://blog.cloudflare.com</link>
        <atom:link href="https://blog.cloudflare.com/" rel="self" type="application/rss+xml"/>
        <language>en-us</language>
        <image>
            <url>https://blog.cloudflare.com/favicon.png</url>
            <title>The Cloudflare Blog</title>
            <link>https://blog.cloudflare.com</link>
        </image>
        <lastBuildDate>Wed, 15 Apr 2026 19:33:09 GMT</lastBuildDate>
        <item>
            <title><![CDATA[Cloudflare Snippets are now Generally Available]]></title>
            <link>https://blog.cloudflare.com/snippets/</link>
            <pubDate>Wed, 09 Apr 2025 14:00:00 GMT</pubDate>
            <description><![CDATA[ Cloudflare Snippets are now generally available, enabling fast, cost-free JavaScript-based HTTP traffic modifications across all paid plans.  ]]></description>
            <content:encoded><![CDATA[ 
    <div>
      <h2>Program your traffic at the edge — fast, flexible, and free</h2>
      <a href="#program-your-traffic-at-the-edge-fast-flexible-and-free">
        
      </a>
    </div>
    <p><a href="https://developers.cloudflare.com/rules/snippets/"><u>Cloudflare Snippets</u></a> are <b>now generally available (GA)</b> for all paid plans, giving you a fast, flexible way to control HTTP traffic using lightweight JavaScript “code rules” — at no extra cost.</p><p>Need to transform headers dynamically, fine-tune <a href="https://www.cloudflare.com/learning/cdn/what-is-caching/">caching</a>, rewrite URLs, retry failed requests, replace expired links, throttle suspicious traffic, or validate authentication tokens? Snippets provide a production-ready solution built for performance, security, and control.</p><p>With GA, we’re introducing a new <a href="https://developers.cloudflare.com/changelog/2025-01-29-snippets-code-editor/"><u>code editor</u></a> to streamline writing and testing logic. This summer, we’re also rolling out an integration with <a href="https://blog.cloudflare.com/secrets-store-beta/"><u>Secrets Store</u></a> — enabling you to bind and manage sensitive values like API keys directly in Snippets, securely and at scale.</p>
    <div>
      <h2>What are Snippets?</h2>
      <a href="#what-are-snippets">
        
      </a>
    </div>
    <p>Snippets bring the power of JavaScript to <a href="https://developers.cloudflare.com/rules/"><u>Cloudflare Rules</u></a>, letting you write logic that runs before a request reaches your origin or after a response returns from upstream. They’re ideal when built-in rule actions aren’t quite enough. While Cloudflare Rules let you define traffic logic without code, Snippets extend that model with greater flexibility for advanced scenarios.</p><p>Think of Snippets as the ultra-fast <b>“code layer” </b>of <a href="https://developers.cloudflare.com/rules/"><u>Cloudflare Rules</u></a>: the <a href="https://developers.cloudflare.com/ruleset-engine/"><u>Ruleset Engine</u></a> evaluates your rules and invokes your code, which then runs on the <a href="https://developers.cloudflare.com/workers/runtime-apis/"><u>Workers runtime</u></a>.</p>
    <div>
      <h3>Key capabilities of Snippets:</h3>
      <a href="#key-capabilities-of-snippets">
        
      </a>
    </div>
    <ul><li><p><b>Ultra-fast execution</b>: optimized for speed with the <a href="https://developers.cloudflare.com/ruleset-engine/"><u>Ruleset Engine</u></a> and <a href="https://developers.cloudflare.com/workers/runtime-apis/"><u>Workers runtime</u></a>.</p></li><li><p><b>Granular request matching</b>: trigger Snippets based on <a href="https://developers.cloudflare.com/ruleset-engine/rules-language/fields/reference/http.request.full_uri/"><u>URI</u></a>, <a href="https://developers.cloudflare.com/ruleset-engine/rules-language/fields/reference/http.user_agent/"><u>user-agent</u></a>, <a href="https://developers.cloudflare.com/ruleset-engine/rules-language/fields/reference/http.request.cookies/"><u>cookies</u></a>, headers and more.</p></li><li><p><b>Sequential execution</b>: <a href="https://developers.cloudflare.com/rules/snippets/how-it-works/"><u>run</u></a> multiple Snippets on the same request, applying modifications step by step.</p></li><li><p>Native <a href="https://developers.cloudflare.com/rules/"><u>Cloudflare Rules</u></a> integration: Snippets <a href="https://developers.cloudflare.com/ruleset-engine/reference/phases-list/#request-phases"><u>inherit</u></a> request modifications from other Cloudflare products.</p></li><li><p>JavaScript and Web APIs support, plus essential <a href="https://developers.cloudflare.com/workers/runtime-apis/"><u>Workers runtime</u></a> features:</p><ul><li><p><a href="https://developers.cloudflare.com/workers/runtime-apis/fetch/"><u>fetch API</u></a></p></li><li><p><a href="https://developers.cloudflare.com/workers/runtime-apis/cache/"><u>cache API</u></a></p></li><li><p><a href="https://developers.cloudflare.com/workers/runtime-apis/request/#incomingrequestcfproperties"><u>request.cf object</u></a></p></li><li><p><a href="https://developers.cloudflare.com/workers/runtime-apis/html-rewriter/"><u>HTMLRewriter</u></a></p></li></ul></li><li><p>Automated deployment and versioning via <a href="https://developers.cloudflare.com/rules/snippets/create-terraform/"><u>Terraform</u></a>.</p></li></ul><p>Best of all? Snippets are <a href="https://developers.cloudflare.com/rules/snippets/#availability"><u>included</u></a> at no extra cost for Pro, Business, and Enterprise plans — with <b>no usage-based fees</b>.</p>
    <div>
      <h2>The journey to GA: How Snippets became production-grade</h2>
      <a href="#the-journey-to-ga-how-snippets-became-production-grade">
        
      </a>
    </div>
    <p>Cloudflare Snippets started as a bold idea: bring the power of JavaScript-based logic to Cloudflare Rules, without the complexity of a full-stack developer platform.</p><p>Over the past two years, Snippets have evolved into a production-ready “code rules” solution, shaping the future of HTTP traffic control.</p><p><b>2022:</b> Cloudflare Snippets were <a href="https://blog.cloudflare.com/snippets-announcement/"><u>announced</u></a> during Developer Week as a solution for users needing flexible HTTP traffic modifications without a full Worker.</p><p><b>2023:</b> <b>Alpha launch </b>— hundreds of users tested Snippets for high-performance traffic logic.</p><p><b>2024:</b> <b>7x traffic growth</b>, processing 17,000 requests per second. Terraform support and production-grade backend were released.</p><p><b>2025:</b> <b>General Availability </b>— Snippets introduces a <a href="https://developers.cloudflare.com/changelog/2025-01-29-snippets-code-editor/"><u>new code editor</u></a>, <a href="https://developers.cloudflare.com/changelog/2025-02-12-rules-upgraded-limits/"><u>increased limits</u></a> alongside other Cloudflare Rules products, integration with <a href="https://developers.cloudflare.com/fundamentals/trace-request/#_top"><u>Trace</u></a>, and a production-grade experience built for scale, handling <b>over 2 million requests per second</b> at peak. Integration with the Secrets Store is rolling out this summer.</p>
          <figure>
          <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/1fZv7cpSGntSQadS761Zkv/31707075a85d393f4883b190599581f7/1.png" />
          </figure>
    <div>
      <h2>New: Snippets + Trace</h2>
      <a href="#new-snippets-trace">
        
      </a>
    </div>
    <p><a href="https://developers.cloudflare.com/fundamentals/trace-request/#_top"><u>Cloudflare Trace</u></a> now shows exactly which Snippets were triggered on a request. This makes it easier to debug traffic behavior, verify logic execution, and understand how your Snippets interact with other products in the request pipeline.</p><p>Whether you’re fine-tuning header logic or troubleshooting a routing issue, Trace gives you real-time insight into how your edge logic behaves in production.</p><div>
  
</div>
<p></p>
    <div>
      <h2>Coming soon: Snippets + Secrets Store</h2>
      <a href="#coming-soon-snippets-secrets-store">
        
      </a>
    </div>
    <p>In the third quarter, you’ll be able to securely access API keys, authentication tokens, and other sensitive values from <a href="https://blog.cloudflare.com/secrets-store-beta/"><u>Secrets Store</u></a> directly in your Snippets. No more plaintext secrets in your code, no more workarounds.</p>
          <figure>
          <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/51QyhWrvtGEQ568lzuqRD/f8eb60c0258d28ef1431fad7f5d03b12/2.png" />
          </figure><p>Once rolled out, secrets can be configured for Snippets via the <a href="https://developers.cloudflare.com/rules/snippets/create-dashboard/"><u>dashboard</u></a> or <a href="https://developers.cloudflare.com/rules/snippets/create-api/"><u>API</u></a> under the new <b>“Settings”</b> button.</p>
          <figure>
          <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/2ipprc9qz2mPpp7XGOURgH/47112dde677906746ef4f798d5c082c0/3.png" />
          </figure>
    <div>
      <h2>When to use Snippets vs. Cloudflare Workers</h2>
      <a href="#when-to-use-snippets-vs-cloudflare-workers">
        
      </a>
    </div>
    <p>Snippets are fast, flexible, and free, but how do they compare to Cloudflare Workers? Both allow you to programmatically control traffic. However, they solve different problems:</p><div>
    <figure>
        <table>
            <colgroup>
                <col></col>
                <col></col>
                <col></col>
            </colgroup>
            <tbody>
                <tr>
                    <td>
                        <p><span><span><strong>Feature</strong></span></span></p>
                    </td>
                    <td>
                        <p><span><span><strong>Snippets</strong></span></span></p>
                    </td>
                    <td>
                        <p><span><span><strong>Workers</strong></span></span></p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p><span><span>Execute scripts based on request attributes (headers, geolocation, cookies, etc.)</span></span></p>
                    </td>
                    <td>
                        <p><span><span>✅</span></span></p>
                    </td>
                    <td>
                        <p><span><span>❌</span></span></p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p><span><span>Modify HTTP requests/responses or serve a different response</span></span></p>
                    </td>
                    <td>
                        <p><span><span>✅</span></span></p>
                    </td>
                    <td>
                        <p><span><span>✅</span></span></p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p><span><span>Add, remove, or rewrite headers dynamically</span></span></p>
                    </td>
                    <td>
                        <p><span><span>✅</span></span></p>
                    </td>
                    <td>
                        <p><span><span>✅</span></span></p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p><span><span>Cache</span></span><span><span> assets at the edge</span></span></p>
                    </td>
                    <td>
                        <p><span><span>✅</span></span></p>
                    </td>
                    <td>
                        <p><span><span>✅</span></span></p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p><span><span>Route traffic dynamically between origins</span></span></p>
                    </td>
                    <td>
                        <p><span><span>✅</span></span></p>
                    </td>
                    <td>
                        <p><span><span>✅</span></span></p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p><span><span>Authenticate</span></span><span><span> requests, pre-sign URLs, run A/B testing</span></span></p>
                    </td>
                    <td>
                        <p><span><span>✅</span></span></p>
                    </td>
                    <td>
                        <p><span><span>✅</span></span></p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p><span><span>Perform compute-intensive tasks (e.g., AI inference, image processing)</span></span></p>
                    </td>
                    <td>
                        <p><span><span>❌</span></span></p>
                    </td>
                    <td>
                        <p><span><span>✅</span></span></p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p><span><span>Store persistent data (e.g., KV, Durable Objects, D1)</span></span></p>
                    </td>
                    <td>
                        <p><span><span>❌</span></span></p>
                    </td>
                    <td>
                        <p><span><span>✅</span></span></p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p><span><span>Deploy via CLI (Wrangler)</span></span></p>
                    </td>
                    <td>
                        <p><span><span>❌</span></span></p>
                    </td>
                    <td>
                        <p><span><span>✅</span></span></p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p><span><span>Use TypeScript, Python, Rust or other programming languages</span></span></p>
                    </td>
                    <td>
                        <p><span><span>❌</span></span></p>
                    </td>
                    <td>
                        <p><span><span>✅</span></span></p>
                    </td>
                </tr>
            </tbody>
        </table>
    </figure>
</div><p><b>Use Snippets when:</b></p><ul><li><p>You need ultra-fast conditional traffic modifications directly on Cloudflare’s network.</p></li><li><p>You want to extend Cloudflare Rules beyond built-in actions.</p></li><li><p>You need free, unlimited invocations within the <a href="https://developers.cloudflare.com/rules/snippets/#limits"><u>execution limits</u></a>.</p></li><li><p>You are migrating from VCL, Akamai’s EdgeWorkers, or on-premise logic.</p></li></ul><p><b>Use Workers when:</b></p><ul><li><p>Your application requires state management, Developer Platform product integrations, or high compute limits.</p></li><li><p>You are building APIs, full-stack applications, or complex workflows.</p></li><li><p>You need logging, debugging tools, CLI support, and gradual rollouts.</p></li></ul><p>Still unsure? Check out our <a href="https://developers.cloudflare.com/rules/snippets/when-to-use/"><u>detailed guide</u></a> for best practices.</p>
    <div>
      <h2>Snippets in action: real-world use cases</h2>
      <a href="#snippets-in-action-real-world-use-cases">
        
      </a>
    </div>
    <p>Below are practical use cases demonstrating Snippets. Each script can be dynamically triggered using our powerful <a href="https://developers.cloudflare.com/ruleset-engine/rules-language/"><u>Rules</u></a> language, so you can granularly control which requests your Snippets will be applied to.</p>
    <div>
      <h3>1. Dynamically modify headers</h3>
      <a href="#1-dynamically-modify-headers">
        
      </a>
    </div>
    <p>Inject custom headers, remove unnecessary ones, and tweak values on the fly:</p>
            <pre><code>export default {
  async fetch(request) {
    const timestamp = Date.now().toString(16); // convert timestamp to HEX
    const modifiedRequest = new Request(request, { headers: new Headers(request.headers) });
    modifiedRequest.headers.set("X-Hex-Timestamp", timestamp); // send HEX timestamp to upstream

    const response = await fetch(modifiedRequest);
    const newResponse = new Response(response.body, response); // make response from upstream mutable

    newResponse.headers.append("x-snippets-hello", "Hello from Cloudflare Snippets"); // add new response header
    newResponse.headers.delete("x-header-to-delete"); // delete response header
    newResponse.headers.set("x-header-to-change", "NewValue"); // replace the value of existing response header

    return newResponse;
  },
};</code></pre>
            
    <div>
      <h3>2. Serve a custom maintenance page</h3>
      <a href="#2-serve-a-custom-maintenance-page">
        
      </a>
    </div>
    <p>Route traffic to a maintenance page when your origin is undergoing planned maintenance:</p>
            <pre><code>export default {
    async fetch(request) { // for all matching requests, return predefined HTML response with 503 status code
        return new Response(`
            &lt;!DOCTYPE html&gt;
            &lt;html lang="en"&gt;
            &lt;head&gt;
                &lt;meta charset="UTF-8"&gt;
                &lt;title&gt;We'll Be Right Back!&lt;/title&gt;
                &lt;style&gt; body { font-family: Arial, sans-serif; text-align: center; padding: 20px; } &lt;/style&gt;
            &lt;/head&gt;
            &lt;body&gt;
                &lt;h1&gt;We'll Be Right Back!&lt;/h1&gt;
                &lt;p&gt;Our site is undergoing maintenance. Check back soon!&lt;/p&gt;
            &lt;/body&gt;
            &lt;/html&gt;
        `, { status: 503, headers: { "Content-Type": "text/html" } });
    }
};</code></pre>
            
    <div>
      <h3>3. Retry failed requests to a backup origin</h3>
      <a href="#3-retry-failed-requests-to-a-backup-origin">
        
      </a>
    </div>
    <p>Ensure reliability by automatically rerouting requests when your primary origin returns an unexpected response:</p>
            <pre><code>export default {
  async fetch(request) {
    const response = await fetch(request); // send original request to the origin

    if (!response.ok &amp;&amp; !response.redirected) { // if response is not 200 OK or a redirect, send to another origin
      const newRequest = new Request(request); // clone the original request to construct a new request
      newRequest.headers.set("X-Rerouted", "1"); // add a header to identify a re-routed request at the new origin
      const url = new URL(request.url); // clone the original URL
      url.hostname = "backup.example.com"; // send request to a different origin / hostname
      return await fetch(url, newRequest); // serve response from the backup origin
    }

    return response; // otherwise, serve response from the primary origin
  },
};</code></pre>
            
    <div>
      <h3>4. Redirect users based on their location</h3>
      <a href="#4-redirect-users-based-on-their-location">
        
      </a>
    </div>
    <p>Send visitors to region-specific sites for better localization:</p>
            <pre><code>export default {
    async fetch(request) {
        const country = request.cf.country; // identify visitor's country using request.cf property
        const redirectMap = { US: "https://example.com/us", EU: "https://example.com/eu" }; // define redirects for each country
        if (redirectMap[country]) return Response.redirect(redirectMap[country], 301); // redirect on match
        return fetch(request); // otherwise, proceed to upstream normally
    }
};</code></pre>
            
    <div>
      <h2>Getting started with Snippets</h2>
      <a href="#getting-started-with-snippets">
        
      </a>
    </div>
    <p>Snippets are available right now in the Cloudflare dashboard under <b>Rules &gt; Snippets</b>:</p><ol><li><p>Go to Rules → Snippets.</p></li><li><p>Use prebuilt <a href="https://developers.cloudflare.com/rules/examples/"><u>templates</u></a> or write your own JavaScript code.</p></li><li><p>Configure a flexible rule to trigger your Snippet.</p></li><li><p>Test and deploy instantly.</p></li><li><p>Automate via <a href="https://developers.cloudflare.com/rules/snippets/create-api/"><u>API</u></a> or <a href="https://developers.cloudflare.com/rules/snippets/create-terraform/"><u>Terraform</u></a>.</p></li></ol>
    <div>
      <h2>Try Snippets today</h2>
      <a href="#try-snippets-today">
        
      </a>
    </div>
    <p>Cloudflare Snippets are now generally available, bringing fast, cost-free, and intelligent HTTP traffic control to all paid plans.</p><p>With native integration into Cloudflare Rules and Terraform — and Secrets Store integration coming this summer — Snippets provide the most efficient way to manage advanced traffic logic at scale.</p><p>Explore Snippets in the Cloudflare Dashboard and start optimizing your traffic with lightweight, flexible rules that enhance performance and reduce complexity.</p> ]]></content:encoded>
            <category><![CDATA[Developer Week]]></category>
            <category><![CDATA[Snippets]]></category>
            <category><![CDATA[General Availability]]></category>
            <category><![CDATA[JavaScript]]></category>
            <category><![CDATA[CDN]]></category>
            <category><![CDATA[Edge Rules]]></category>
            <category><![CDATA[Developers]]></category>
            <guid isPermaLink="false">6rBnmM6UiFX8ca7XXlOU2X</guid>
            <dc:creator>Nikita Cano</dc:creator>
        </item>
        <item>
            <title><![CDATA[Cloudflare Snippets is now available in alpha]]></title>
            <link>https://blog.cloudflare.com/cloudflare-snippets-alpha/</link>
            <pubDate>Wed, 21 Jun 2023 13:00:50 GMT</pubDate>
            <description><![CDATA[ Cloudflare Snippets are available in alpha. Snippets are a simple way of executing a small piece of Javascript on select HTTP requests, using the ruleset engine filtering logic ]]></description>
            <content:encoded><![CDATA[ <p></p><p>Today we are excited to announce that <a href="/snippets-announcement/">Cloudflare Snippets</a> is available in alpha. In the coming weeks we will be opening access to our waiting list.</p>
    <div>
      <h3>What are Snippets?</h3>
      <a href="#what-are-snippets">
        
      </a>
    </div>
    <p>Over the past two years we have released a number of new rules products such as Transform Rules, Cache Rules, Origin Rules, Config Rules and Redirect Rules. These new products give more control to customers on how we process their traffic as it flows through our global network. The feedback on these products so far has been overwhelmingly positive. However, our customers still occasionally need the ability to do more than the out-of-the-box functionality allows. Not just adding an HTTP header - but performing some advanced calculation to create the output.</p><p>For these cases, Cloudflare Snippets comes to the rescue. Snippets are small pieces of user created JavaScript that are run by Cloudflare before your website, API or application is served to the user. If you're familiar with <a href="https://developers.cloudflare.com/workers/">Cloudflare Workers</a>, our robust developer platform, then you'll find Snippets to be a familiar addition. For those who are not, Snippets are designed to be easily created, tested, and deployed. Providing you with the ability to deploy your custom JavaScript Snippet to our <a href="https://www.cloudflare.com/network/">global network</a> in a matter of seconds.</p><p>While Snippets are built on top of the Workers Platform, they do have a number of differences. The first lies in how Snippets operate within the <a href="https://developers.cloudflare.com/ruleset-engine/about/rulesets/">Ruleset Engine</a> as a dedicated new phase, similar to <a href="/transform-rules-requests-transform-and-roll-out/">Transform Rules</a> and <a href="/introducing-cache-rules/">Cache Rules</a>. This means that customers can select and execute a Snippet based on any Ruleset Engine filter. This gives customers the flexibility to run a Snippet on every request or apply it selectively based on various criteria they provide, such as specific bot scores, country of origin, or certain cookies.</p><p>Moreover, Snippets are cumulative in nature, allowing users to have multiple Snippets that execute if they meet the defined conditions. For instance, one Snippet could add an HTTP header and another rewrite the URL, both of which will be executed if their respective conditions are met.</p><p>Users now have the flexibility to choose between using a rule for simple, no-code-required tasks, such as adding a basic response Cookie header with Transform Rules, or writing a Cloudflare Snippet for more complex cookie functionality, such as dynamically changing the host or date within the cookie value. Snippets empower customers to get the job done quickly and effortlessly within the Cloudflare ecosystem, without incurring extra expenses (though a fair usage cap applies).</p>
    <div>
      <h3>The difference between Snippets and Workers</h3>
      <a href="#the-difference-between-snippets-and-workers">
        
      </a>
    </div>
    <p>Another significant advantage is that Cloudflare Snippets are available across all plan levels at no extra cost. This empowers customers to migrate their simple workloads from legacy solutions like VCL to the Cloudflare platform, actively reducing their monthly expenses.</p><p>Whether you're on the <a href="https://www.cloudflare.com/plans/free/">Free</a>, Pro, Business, or Enterprise plan, Snippets are at your disposal. Free plan users have access to five Snippets per zone, while Pro, Business, and Enterprise plans offer 10, 25, and 50 Snippets per zone, respectively.</p><p>In terms of resources, Cloudflare Snippets are lightweight compared to Workers. They have a maximum execution time of 5ms, a maximum memory of 2MB, and a total package size of 32KB. These limits are more than sufficient for common use cases like modifying HTTP headers, rewriting URLs, and routing traffic tasks that do not require the additional features and resources Cloudflare Workers has to offer.</p><p>Snippets also run before Workers; this means that users will be able to move simple logic out of a Cloudflare Worker into Snippets or use Cloudflare Workers and its features to further modify a request. The <a href="/traffic-sequence-which-product-runs-first/">Traffic Sequence UI</a> has also been updated to incorporate Snippets allowing you to easily understand how all the products fit together and understand how HTTP requests flow between them.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/6mzGrins7tVyfuUDsaHVYI/d9987a80370fac66c94ec49cac211871/image4-13.png" />
            
            </figure>
    <div>
      <h3>What can you build with Cloudflare Snippets?</h3>
      <a href="#what-can-you-build-with-cloudflare-snippets">
        
      </a>
    </div>
    <p>Snippets allow customers to migrate their existing workloads to Cloudflare. For example, customers that wish to set a dynamic cookie on all of their responses for a percentage of requests can use the `math.random` function within their Snippet.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/6FMCvZXK5bgjhsyzLkFo4G/1641ca4379e1acfc5d1252deee86ffa8/Screenshot-2023-06-12-at-15.40.26.png" />
            
            </figure><p>By leveraging the Ruleset Engine, we can improve the implementation by moving the set cookie logic to the rule instead of executing it on every response or handling it within a Snippet. For example if I only want to set this cookie on my shop subdomain and only for German or UK customers I can create the following rule.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/6hvl6NIA5Qd6JUu9zCJQTl/df6b3c51b85332fd812dd3d032b130ec/pasted-image-0-1.png" />
            
            </figure><p>This approach ensures that the snippet will only execute when necessary, minimizing additional processing and reducing the complexity of the code required.</p><p>We are excited to see what other use cases Cloudflare Snippets unlock for our customers.</p>
    <div>
      <h3>Using Snippets</h3>
      <a href="#using-snippets">
        
      </a>
    </div>
    <p>Snippets are located within the Rules section of the Cloudflare Dashboard. Here customers can use the UI to write, preview and deploy their first Snippet.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/65jEwkBoBxpxT5hDxVcXFX/a108461a9ffad8f23cab13ff8971536b/pasted-image-0--1-.png" />
            
            </figure><p>As with all Cloudflare products users can deploy their Snippets via the API and Terraform. Allowing users to easily incorporate Snippets within their <a href="https://www.cloudflare.com/learning/serverless/glossary/what-is-ci-cd/">CI/CD pipelines</a>. The added benefit of using the Ruleset engine allows users to test their code on a subset of traffic. For example, by specifying your own office IP or secret header within the filter that will only trigger the Snippet if present. Finally we will be integrating Snippets within the <a href="https://developers.cloudflare.com/api/operations/account-request-tracer-request-trace">Account Request Tracer</a> allowing users to easily identify all Rules that are executing on a specific request.</p>
    <div>
      <h3>How did we build Snippets?</h3>
      <a href="#how-did-we-build-snippets">
        
      </a>
    </div>
    <p>During Developer Week, we discussed the process of <a href="/building-cloudflare-on-cloudflare/">Building Cloudflare on Cloudflare</a>, using our Cloudflare Workers developer platform to enhance our products in terms of speed, robustness, and ease of development. Snippets, the latest Cloudflare product, is built on top of Workers for Platforms.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/6ZjJrhzjJN19EPkBsFs1pF/3f926e67df4b3df4efffb03f0163cec9/pasted-image-0--2-.png" />
            
            </figure><p>A snippet is a piece of user-defined JavaScript that, upon creation, generates a unique Snippet ID. This Snippet ID is then associated with a user-defined rule created using the Rule Engine syntax. When a rule is created, a unique Rule ID is assigned to it. The Snippet ID and Rule ID are then linked in a one-to-one relationship. Customers have the flexibility to create multiple snippets and rules, each with its own unique Snippet and Rule. Customers with multiple snippets can easily prioritize them within the user interface (UI) or via API, similar to our other rules-based products.</p><p>When a customer's request reaches Cloudflare, we evaluate the request parameters against the created Snippet rules within a user's zone. If a Snippet rule is matched, the corresponding unique Snippet ID is added to a Snippet table. Once all the rules have been evaluated and the Snippet table has been compiled, the completed table is passed to the Snippets Internal Worker Service.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/5pfQrVdEz8jHYz1pTV7HYI/7da7e12c763efe37bb21a2e23c184ad0/pasted-image-0--3-.png" />
            
            </figure><p>This Worker receives all the Snippet IDs stored within the table that are to be sequentially executed. The system's design allows for the flexibility of keeping Snippets simple, where users can manage individual snippets independently, that execute on the same request. This approach grants users the freedom to control and fine-tune their own individual snippets rather than merging them into a single entity.</p><p>Each Snippet receives the modified request from the previous Snippet and applies new modifications to it. After executing the final Snippet IDs, the resulting modified request is passed back to FL for the next step of the request processing.</p>
    <div>
      <h3>Snip into action</h3>
      <a href="#snip-into-action">
        
      </a>
    </div>
    <p>We are excited to see the innovative use cases that our customers will create with Snippets. In the upcoming weeks, we will start granting access to the alpha version to those on our waitlist. If you haven't joined the waitlist yet, you can still <a href="https://www.cloudflare.com/lp/cloudflare-snippets/">sign up</a> with an open beta available later this year.</p> ]]></content:encoded>
            <category><![CDATA[Speed Week]]></category>
            <category><![CDATA[Snippets]]></category>
            <guid isPermaLink="false">3B2aPfFwadyjcrli2w1yR3</guid>
            <dc:creator>Matt Bullock</dc:creator>
        </item>
        <item>
            <title><![CDATA[How to use Cloudflare Observatory for performance experiments]]></title>
            <link>https://blog.cloudflare.com/performance-experiments-with-cloudflare/</link>
            <pubDate>Tue, 20 Jun 2023 13:00:41 GMT</pubDate>
            <description><![CDATA[ Introducing Cloudflare's Performance Experiments in Observatory: Safely test code, improve website speed, and minimize risk ]]></description>
            <content:encoded><![CDATA[ 
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/10lkfVC0CItfHg3o9li9UE/c76d37c253df38abe5d330f69cfbda21/image1-12.png" />
            
            </figure><p>Website performance is crucial to the success of online businesses. <a href="https://www2.deloitte.com/content/dam/Deloitte/ie/Documents/Consulting/Milliseconds_Make_Millions_report.pdf">Stud</a>y after <a href="https://www.thinkwithgoogle.com/_qs/documents/4290/c676a_Google_MobileSiteSpeed_Playbook_v2.1_digital_4JWkGQT.pdf">study</a> has shown that an increased load time directly affects sales. But how do you get test products that could improve your website speed without incurring an element of risk?</p><p>In today's digital landscape, it is easy to find code optimizations on the Internet including our own <a href="https://developers.cloudflare.com/workers/examples/103-early-hints/">developers documentation</a> to improve the performance of your website or web applications. However, implementing these changes without knowing the impact they’ll have can be daunting. It could also cause an outage, taking websites or applications offline entirely, leaving admins scrambling to remove the offending code and get the business back online.</p><p>Users need a way to see the impact of these improvements on their websites without impacting uptime. They want to understand “If I enabled this, what performance boost should I expect to get?”.</p><p>Today, we are excited to announce Performance Experiments in Cloudflare Observatory. Performance Experiments gives users a safe place to experiment and determine what the best setup is to improve their website performance before pushing it live for all visitors to benefit from. Cloudflare users will be able to simply enter the desired code, run our Observatory testing suite and view the impact it would have on their Lighthouse score. If they are satisfied with the results they can push the experiment live. With the click of a button.</p>
    <div>
      <h3>Experimenting within Observatory</h3>
      <a href="#experimenting-within-observatory">
        
      </a>
    </div>
    <p>Cloudflare Observatory, announced today, allows users to <a href="https://www.cloudflare.com/application-services/solutions/app-performance-monitoring/">easily  monitor website performance</a> by integrating Real-User Monitoring (RUM) data and synthetic tests in one location.. This allows users to easily identify areas for optimization and leverage Cloudflare's features to address performance issues.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/3aQGCB2KNhkS4HWeEiyniP/b88844566de492c58b2280afd56dd71b/Untitled-presentation--3-.png" />
            
            </figure><p>Observatory's recommendations leverage insights from these Lighthouse test and RUM data, enabling precise identification of issues and offering tailored Cloudflare settings for enhanced performance. For example, when a Lighthouse report suggests image optimization improvements, Cloudflare recommends enabling Polish or utilizing Image Resizing. These recommendations can be implemented with a single click, allowing customers to boost their performance score effortlessly.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/3rwkPP32qk8u5cvYWSwWhh/407bbe9e5fe3874fb34beafd0c566bdc/image2-11.png" />
            
            </figure>
    <div>
      <h3>Fine tuning with Experiments</h3>
      <a href="#fine-tuning-with-experiments">
        
      </a>
    </div>
    <p>Cloudflare’s Observatory allows customers to easily enable recommended Cloudflare settings. However,  through the medium of Cloudflare Workers web performance advocates have been able to create and share JavaScript examples of how to improve and optimize a website.</p><p>A great example of this is <a href="/fast-google-fonts-with-cloudflare-workers/">Fast Fonts</a>. Google Fonts are slow due to how they are served. When using Google Fonts on your website, you include a stylesheet URL that contains the font styles you want to use. The CSS file is hosted on one domain (fonts.googleapis.com), while the font files are on another domain (fonts.gstatic.com). This separation means that each resource requires at least four round trips to the server for DNS lookup, establishing the socket connection, negotiating TLS encryption (for https), and making the request itself.</p><p>These requests cannot be done in parallel because the fonts are not known until after the CSS is downloaded and applied to the page. In the best-case scenario, this leads to eight round trips before the text can be displayed. On a slower 3G connection with a 300ms round-trip time, this delay can add up to 2.4 seconds. To fix this issue Cloudflare Workers can be used to reduce the performance penalties of serving Google Fonts directly from Google by 81%.</p><p>Another issue is resource prioritization. When all requests come from the same domain on the same HTTP/2 connection, critical resources like CSS and fonts can be prioritized and delivered before lower priority resources like images. However, since Google Fonts (and most third-party resources) are served from a different domain than the main page resources, they cannot be prioritized and end up competing with each other for download bandwidth. This competition can result in significantly longer fetch times than the best-case scenario of eight round trips.</p><p>To implement this Worker first create a Cloudflare Worker, implement the code from the <a href="https://github.com/cloudflare/workers-sdk/tree/main/templates">GitHub repository</a> using Wrangler and then run manual tests to see if performance has been improved and that there are no issues or problems with the website loading. Users can choose to implement the Cloudflare Worker on a test path that may not be a true reflection of production or complicate the Cloudflare Worker further by implementing an <a href="https://developers.cloudflare.com/workers/examples/ab-testing/">A/B test</a> that could still have an impact on your end users. So how can users test code on their website to easily see if the code will improve the performance of their website and not have any adverse impact on end users?</p>
    <div>
      <h3>Introducing Performance Experiments</h3>
      <a href="#introducing-performance-experiments">
        
      </a>
    </div>
    <p>Last year we announced <a href="/snippets-announcement/">Cloudflare Snippets</a>. Snippets is a platform for running discrete pieces of JavaScript code on Cloudflare before your website is served to the user. They provide a convenient way to customize and enhance your website's functionality. If you are already familiar with Cloudflare Workers, our developer platform, you'll find Snippets to be a familiar and welcome addition to your toolkit. With Snippets, you can easily execute small pieces of user-created JavaScript code to modify the behavior of your website and improve performance, security, and user experience.</p><p>Combining Snippets with Observatory lets users easily run experiments and get instant feedback on the performance impact. Users will be able to find a piece of JavaScript, insert it into the Experiments window and hit test. Observatory will then automatically run multiple Lighthouse tests with the experiment disabled and then enabled. The results will show the before and after scores allowing users to determine the impact of the experiment e.g. “If I put this JavaScript on my website, my Lighthouse score would improve by 15 points”.</p><p>This allows users to understand if the JavaScript has had a positive performance impact on their website. Users can then deploy this JavaScript, via Snippets, against all requests or on a specific subset of traffic. For example, if I only wanted it run on traffic from the UK or my office IPs I would use the rule below:</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/4sf0uU0mxbzy0vpooRtD1I/4dc83c8d9099e1a819c63bbf600e34ca/image3-9.png" />
            
            </figure><p>Alternatively, if the results impact performance customers negatively users can safely discard the experiment or try another example. All without real visitors to the website being impacted or ever at risk.</p>
    <div>
      <h3>Accessing Performance Experiments</h3>
      <a href="#accessing-performance-experiments">
        
      </a>
    </div>
    <p>Performance Experiments are currently under development — you can sign up <a href="https://www.cloudflare.com/lp/performance-experiments/">here</a> to join the waitlist for access.</p><p>We hope to begin admitting users later in the year, with an open beta to follow.</p>
    <div>
      <h3>Watch on Cloudflare TV</h3>
      <a href="#watch-on-cloudflare-tv">
        
      </a>
    </div>
    <div></div> ]]></content:encoded>
            <category><![CDATA[Speed Week]]></category>
            <category><![CDATA[Snippets]]></category>
            <category><![CDATA[Performance]]></category>
            <guid isPermaLink="false">5pLrwEWCzaYn7Eidb2mu5H</guid>
            <dc:creator>Matt Bullock</dc:creator>
            <dc:creator>Sam Marsh</dc:creator>
        </item>
        <item>
            <title><![CDATA[The most programmable Supercloud with Cloudflare Snippets]]></title>
            <link>https://blog.cloudflare.com/snippets-announcement/</link>
            <pubDate>Thu, 17 Nov 2022 14:00:00 GMT</pubDate>
            <description><![CDATA[ Today we are announcing Cloudflare Snippets. Snippets are a simple way of executing a small piece of Javascript on select HTTP requests, using the ruleset engine filtering logic. ]]></description>
            <content:encoded><![CDATA[ 
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/1OJBcvw1RLIv4SmqBQoDVE/12f4e3f81b9aff4ecc7a62c7017c98c2/image3-28.png" />
            
            </figure>
    <div>
      <h2>Your traffic, how you like it</h2>
      <a href="#your-traffic-how-you-like-it">
        
      </a>
    </div>
    <p>Cloudflare is used by a highly diverse customer base. We offer simple-to-use products for everything from setting HTTP headers to rewriting the URI path and performing URL redirects. Sometimes customers need more than the out-of-the-box functionality, not just adding an HTTP header - but performing some advanced calculation to create the output. Today they would need to create a feature request and wait for it to be shipped, write a <a href="https://workers.cloudflare.com/">Cloudflare Worker</a>, or keep this modification ‘on origin’ - on their own infrastructure.</p><p>To simplify this, we are delighted to announce Cloudflare Snippets. Snippets are a new way to perform traffic modifications that users either cannot do via our productised offerings, or want to do programmatically. The best part? The vast majority of customers will pay <i>nothing extra</i> for using Snippets.</p><p>Users now have a choice. Perform the action via a rule. Or, if more functionality is needed, write a Snippet.  Neither will mean waiting. Neither will incur additional cost (although a high fair usage cap will apply). Snippets unblocks users to do what they want, when they want. All on Cloudflare.</p><p>Snippets will support the import of code written in various languages, such as JavaScript (modern), VCL (legacy) and Apache .htaccess files (legacy). This allows customers to migrate legacy operational code onto our platform - whilst also consolidating their JavaScript operations.</p><p>Please use the sign-up form to join the waitlist for Snippets if you are interested in testing. We hope to begin admitting users into the closed beta early 2023.</p>
    <div>
      <h2>Why build Snippets?</h2>
      <a href="#why-build-snippets">
        
      </a>
    </div>
    <p>Over the past 18 months we have released a number of new rules products such as <a href="/introducing-transform-rules-with-url-rewriting-at-the-edge/">Transform Rules,</a> <a href="/introducing-cache-rules/">Cache Rules</a>, <a href="/origin-rules/">Origin Rules</a>, <a href="/configuration-rules/">Config Rules</a> and <a href="/dynamic-redirect-rules/">Redirect Rules</a>. These new products give more control to customers on how we process their traffic as it flows through our global network. The feedback on these products so far has been overwhelmingly positive. However, our customers still occasionally need the ability to do more than the out-of-the-box functionality allows.</p><p>There are always some use cases where a product doesn’t provide the functionality that a customer needs for their specific situation.  For example, whilst thousands of our customers are now using Transform Rules to solve their HTTP header modification use cases, there remains a small number of use cases that are not possible, such as setting dynamic expiry times with cookies or hashing tokens with a key.</p><p>This is where Cloudflare Snippets help. Customers will no longer need to use the full Cloudflare Workers platform to implement these relatively simple use cases. Nor will they need to wait for us to build their feature requests. Instead, they will be able to run a Snippet of JavaScript.</p>
    <div>
      <h2>Migrating legacy code to Snippets</h2>
      <a href="#migrating-legacy-code-to-snippets">
        
      </a>
    </div>
    <p><a href="https://varnish-cache.org/docs/trunk/users-guide/vcl.html">Varnish Control Language</a> (VCL) is only used within the context of Varnish. Launched around 16 years ago, it has historically been used to configure traffic and routing for <a href="https://www.cloudflare.com/learning/cdn/what-is-a-cdn/">Content Delivery Networks</a> as it was extensible to a wide range of use cases.</p><p>There are still a good number of businesses out there using VCL to perform routing and traffic modification actions. Whilst other providers are deprecating support for VCL, we want to make sure those of you comfortable using it are still supported.</p><p>Snippets won't run pure VCL. Instead, we will convert VCL into easy to maintain rules or Snippets. To achieve this we’re building a simple-to-use, self-serve VCL converter that analyzes uploaded VCL code and auto-generates suggested Snippets, and if we can find a match, also generates suggested rules for products such as Transform Rules or Cache Rules.</p><p>This topic was initially handled via <a href="/announcing-turpentine/">Project Turpentine</a>, a suite of tools used by Cloudflare employees to parse a customer’s VCL into a suggested JavaScript configuration. This JavaScript could then be loaded into a Worker, or series of Workers.</p><p>Snippets takes the idea and principles of Turpentine further. Much further. By building a parser directly in the dashboard it puts the power directly into the hands of users and gives them a choice. You can tell us to migrate everything we can into Rules with the remaining code migrated into Snippets, or, you can choose to tell us to migrate everything into discrete Snippets. It's your call.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/7783datzERcQclqZ8Ey84u/12736fcb80fffecbdb6a73f7053e9deb/image1-55.png" />
            
            </figure><p>We’ll give Apache <a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/Apache_Configuration_htaccess">htaccess</a> and NGINX <a href="https://www.nginx.com/resources/wiki/start/topics/examples/full/">configuration files</a> the same treatment. The goal being users simply upload the files from their websites Apache or NGINX configuration, and we generate suggested Snippets and/or rules.</p><p>The days of having to use legacy code for operational tasks are coming to an end. Snippets allow users to migrate these workloads to Cloudflare, and let them focus on the bigger problems of the business vs maintaining legacy systems.</p>
    <div>
      <h2>The difference between Snippets and Workers</h2>
      <a href="#the-difference-between-snippets-and-workers">
        
      </a>
    </div>
    <p>Most readers will already be familiar with Cloudflare Workers, our powerful developer platform which allows businesses to run and build entire products and solutions on Cloudflare's global network. Snippets is also built on this platform, but has a few key differences.</p><p>The first major difference is that a Snippet will run as part of the <a href="https://developers.cloudflare.com/ruleset-engine/">Ruleset Engine</a> as dedicated new <i>phases</i>, similar to Transform Rules and Cache Rules. Customers will be able to select and execute a Snippet based on any <a href="https://developers.cloudflare.com/ruleset-engine/rules-language/fields">ruleset engine filter</a>. This allows customers to run a Snippet against every request, or filter for specific HTTP traffic based on the fields we offer, such as traffic with a certain bot score, originating from a specific country, or with a specific cookie. Snippets will be additive, meaning users can have one Snippet to add an HTTP header, and another to rewrite the URL, and both will execute if they match:</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/1RAJyoslLJf0Q7yiGjqTiD/1b0b09e884088b571e513fd8225e8892/image2-39.png" />
            
            </figure><p>Another major difference - Cloudflare Snippets are available for all plan levels, at no additional cost. 99% of users won't pay a single cent, ever, to use this solution. This allows customers to migrate their simple workloads from legacy solutions like VCL to the Cloudflare platform, and actively reduce their monthly spend.</p><table>
<thead>
  <tr>
    <th></th>
    <th>Free Plans</th>
    <th>Pro Plans</th>
    <th> Business Plans</th>
    <th>Enterprise Plans</th>
  </tr>
</thead>
<tbody>
  <tr>
    <td>Snippets available</td>
    <td>5 Snippets per zone.</td>
    <td>20 Snippets per zone.</td>
    <td>50 Snippets per zone.</td>
    <td>200 Snippets per zone*<br />(Customers can speak with their Customer Success team to have this increased).</td>
  </tr>
</tbody>
</table><p>Cloudflare Snippets are lightweight when compared with Workers, offering 5ms maximum execution time, 2MB maximum memory and 32KB total package size. This comparably small footprint allows us to offer this to 99% of users at no additional cost, whilst also being sufficient for the identified use cases like HTTP header modification, URL rewriting and traffic routing - all of which don't need the vast resources offered by Cloudflare Workers.</p><table>
<thead>
  <tr>
    <th></th>
    <th>Cloudflare Snippets</th>
    <th>Cloudflare Workers Unbound<br />(For comparison)</th>
  </tr>
</thead>
<tbody>
  <tr>
    <td>Runtime support</td>
    <td>JavaScript</td>
    <td>JavaScript and WASM</td>
  </tr>
  <tr>
    <td>Execution location</td>
    <td>Global - All Cloudflare locations</td>
    <td>Global - All Cloudflare locations</td>
  </tr>
  <tr>
    <td>Triggers supported</td>
    <td>Ruleset Engine Filters</td>
    <td>HTTP Request<br />HTTP Response<br />Cron Triggers</td>
  </tr>
  <tr>
    <td>Maximum execution time</td>
    <td>5ms</td>
    <td>30 Seconds HTTP<br />15 Minutes (Cron Trigger)</td>
  </tr>
  <tr>
    <td>Maximum memory</td>
    <td>2MB</td>
    <td>128MB</td>
  </tr>
  <tr>
    <td>Total package size</td>
    <td>32KB</td>
    <td>5MB</td>
  </tr>
  <tr>
    <td>Environment variables</td>
    <td>8/Snippet</td>
    <td>64/Worker</td>
  </tr>
  <tr>
    <td>Environment variable size</td>
    <td>1KB</td>
    <td>5KB</td>
  </tr>
  <tr>
    <td>Subrequests</td>
    <td>1/request</td>
    <td>1000/request</td>
  </tr>
  <tr>
    <td>Terraform Support</td>
    <td>✅</td>
    <td>✅</td>
  </tr>
  <tr>
    <td>Wrangler Support</td>
    <td></td>
    <td>✅</td>
  </tr>
  <tr>
    <td>Cron Triggers</td>
    <td></td>
    <td>✅</td>
  </tr>
  <tr>
    <td>Key Value Store</td>
    <td></td>
    <td>✅</td>
  </tr>
  <tr>
    <td>Durable Objects</td>
    <td></td>
    <td>✅</td>
  </tr>
  <tr>
    <td>R2 Integration</td>
    <td></td>
    <td>✅</td>
  </tr>
</tbody>
</table>
    <div>
      <h2>What will you be able to build with Cloudflare Snippets?</h2>
      <a href="#what-will-you-be-able-to-build-with-cloudflare-snippets">
        
      </a>
    </div>
    <p>Snippets will allow customers to migrate their existing workloads to Cloudflare. They will also open up a number of new possible use cases for customers. We have highlighted three common examples below, however there are many more to choose from.</p>
    <div>
      <h3>Example 1: Sending suspect bots to a honeypot</h3>
      <a href="#example-1-sending-suspect-bots-to-a-honeypot">
        
      </a>
    </div>
    <p>When creating Snippets customers will be able to access Cloudflare <a href="https://developers.cloudflare.com/workers/runtime-apis/request/">features</a> available in the Workers runtime, such as the bot score field. This enables customers to forward an HTTP request to a honeypot or use the RegExp Javascript function to change the URL construct being sent back to the end user when traffic is assigned a bot score below a certain threshold, e.g. <a href="https://developers.cloudflare.com/bots/concepts/bot-score/#:~:text=A%20bot%20score%20is%20a,request%20came%20from%20a%20human.">29 and lower</a>.</p>
            <pre><code>…
if (request.cf.botManagement.score &lt; 30) {
const honeypot = "https://example.com/";
return await fetch(honeypot, request);
…
}</code></pre>
            
    <div>
      <h3>Example 2: Cookie modification</h3>
      <a href="#example-2-cookie-modification">
        
      </a>
    </div>
    <p>Another common use case we foresee Snippets addressing is cookie modification. Usage can range from simply setting an expiry in five minutes by using <code>getTime</code> and <code>setTime</code> JavaScript functions to setting a dynamic cookie based on user request attributes for A/B testing purposes.</p>
            <pre><code>…
{
let res = await fetch(request);
res = new Response(res.body, res);
// 24h * 60m * 60s * 1000ms = 86400000ms
const expiry = new Date(Date.now() + 7 * 86400000).toUTCString();
const group = request.headers.get("userGroup") == "premium" ? "A" : "B";
res.headers.append(
      "Set-Cookie",
`testGroup=${group}; Expires=${expiry}; path=/`
    );
…</code></pre>
            
    <div>
      <h3>Example 3: URI query management</h3>
      <a href="#example-3-uri-query-management">
        
      </a>
    </div>
    <p>Customers can also deploy Cloudflare Snippets to do complex operations such as splicing the URI query value to selectively remove or inject additional parameters. Query string manipulation is typically done using Transform Rules. However, with Transform Rules the <code>set/</code> action is effectively a <code>replace</code> action. This action when applied to the URI query string will remove the entire value if there is one and set it to what the user specifies, thus overwriting it. This is a problem for customers who wish to selectively inject specific query parameters for matching traffic. For example,  setting an additional query, e.g. <code>?utm_campaign=facebook</code> when common social media platforms are detected in the user agent. With Snippets, customers will be able to do this selective removal and insertion using a simple piece of JavaScript, e.g.</p>
            <pre><code>…
if (userAgent.includes("Facebook")) {
      const url = new URL(request.url);
      const params = new URLSearchParams(url.search);
      params.set("utm_campaign", "facebook");
      url.search = params.toString();
      const transformedRequest = new Request(url, request)
…
}</code></pre>
            <p>We are excited to see what other use cases Cloudflare Snippets unlock for our customers.</p>
    <div>
      <h2>Will you stop adding actions to rulesets?</h2>
      <a href="#will-you-stop-adding-actions-to-rulesets">
        
      </a>
    </div>
    <p>The simple answer is no! We will continue to build out our no-code actions within the ruleset engine, developing new products to solve customer needs.</p><p>It may sound obvious - but a core component to feature improvement is talking to customers. Talking to Snippet users will help us understand what real life use cases Snippets help solve and highlight feature gaps we have in our product suite. We can then review if it makes sense to productise that use case, or leave it requiring Snippets.</p><p>We also understand that not everyone is a software developer. We are therefore exploring how we can make Snippets accessible to all by creating selectable templates available in a library that can be copied and modified by customers, with minimum coding knowledge required. With Snippets, powerful won’t mean difficult.</p>
    <div>
      <h2>Accessing Cloudflare Snippets</h2>
      <a href="#accessing-cloudflare-snippets">
        
      </a>
    </div>
    <p>Snippets are currently under development — you can sign up <a href="https://www.cloudflare.com/lp/cloudflare-snippets/">here</a> to join the waitlist for access.</p><p>We hope to begin admitting users into the closed beta in early 2023, with an open beta to follow.</p> ]]></content:encoded>
            <category><![CDATA[Developer Week]]></category>
            <category><![CDATA[Snippets]]></category>
            <category><![CDATA[JavaScript]]></category>
            <guid isPermaLink="false">zV6omBtZzUdVJucURgijz</guid>
            <dc:creator>Sam Marsh</dc:creator>
        </item>
    </channel>
</rss>