PHPackages                             studioraz/magento2-cloudflare - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. studioraz/magento2-cloudflare

ActiveMagento2-module[Utility &amp; Helpers](/categories/utility)

studioraz/magento2-cloudflare
=============================

Magento 2 module

1.7.0(1mo ago)910↓90.9%2MITPHPPHP ^8.1CI passing

Since Sep 29Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/studioraz/magento2-cloudflare)[ Packagist](https://packagist.org/packages/studioraz/magento2-cloudflare)[ RSS](/packages/studioraz-magento2-cloudflare/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (10)Dependencies (6)Versions (22)Used By (0)

Magento 2 Cloudflare Integration
================================

[](#magento-2-cloudflare-integration)

Use Cloudflare as your Magento 2 full-page cache and image optimization CDN.

[![Latest Version](https://camo.githubusercontent.com/ce6a4362dc806e3b5eed7e0df577b2e25a2ed89897930ad36aa0849164ece6a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73747564696f72617a2f6d6167656e746f322d636c6f7564666c6172652e737667)](https://packagist.org/packages/studioraz/magento2-cloudflare)[![License: MIT](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

---

Table of Contents
-----------------

[](#table-of-contents)

1. [Overview](#overview)
2. [Features](#features)
3. [Prerequisites](#prerequisites)
4. [Installation](#installation)
5. [Configuration](#configuration)
    - [General Settings (Image Optimization)](#general-settings-image-optimization)
    - [Cache (FPC) Settings](#cache-fpc-settings)
6. [How It Works](#how-it-works)
7. [Deploying the Cloudflare Worker](#deploying-the-cloudflare-worker)
    - [Deployment Steps](#deployment-steps)
    - [Worker Environment Variables](#worker-environment-variables)
8. [Automatic Cache Purging](#automatic-cache-purging)
9. [Image Optimization](#image-optimization)
10. [Troubleshooting](#troubleshooting)
11. [Contributing](#contributing)
12. [License](#license)

---

Overview
--------

[](#overview)

Magento's built-in full-page cache and Varnish setups require significant server-side infrastructure to manage, scale, and keep in sync with content changes. Image optimization typically adds another layer of complexity with local cache directories and third-party services.

This module replaces all of that with [Cloudflare](https://www.cloudflare.com/):

1. **Full-Page Cache (FPC)** -- use Cloudflare's global CDN as a drop-in replacement for Varnish or the built-in FPC. A bundled Cloudflare Worker handles caching logic at the edge, replicating Magento's Varnish behavior without requiring you to manage Varnish servers.
2. **Image Optimization** -- automatically rewrite image URLs to Cloudflare's `/cdn-cgi/image/` endpoint. Images are resized, converted to modern formats (WebP, AVIF), and served from the edge -- no local image cache needed.

Developed and maintained by [Studio Raz](https://studioraz.co.il/) and released as open-source for the Magento community.

---

Features
--------

[](#features)

### Full-Page Cache

[](#full-page-cache)

- Use Cloudflare as a selectable caching application alongside Built-in and Varnish
- Smart cache invalidation -- only affected pages are purged when content changes, not the entire cache
- Automatic cleanup of 50+ marketing/tracking query parameters (UTM, Facebook, Google Ads, etc.) to improve cache hit rates
- GraphQL cache support with proper cache key handling
- Configurable TTL, bypass paths, and debug headers
- Hit-for-pass mechanism prevents cache pollution from uncacheable pages

### Image Optimization

[](#image-optimization)

- Automatic image URL rewriting to Cloudflare's image resizing pipeline
- Serves images in the best format the browser supports (WebP, AVIF, or original)
- Configurable quality (1--100) and fit mode per store view
- Covers product images, CMS content, logos, and widget images
- Eliminates local image cache generation, reducing disk usage and deployment size
- Debug logging available for API troubleshooting

---

Prerequisites
-------------

[](#prerequisites)

### Cloudflare

[](#cloudflare)

- A Cloudflare account with your domain proxied through Cloudflare (orange cloud icon enabled)
- **For FPC:** A [Cloudflare Workers](https://workers.cloudflare.com/) subscription. The free tier allows 100,000 requests/day; the paid plan ($5/month) includes 10 million requests/month.
- **For Image Optimization:** [Cloudflare Images](https://developers.cloudflare.com/images/) is available on all plans. The free tier includes 5,000 unique transformations/month. For higher volumes, the paid plan costs $0.50 per 1,000 unique transformations.
- A Cloudflare **API Token** with the **Zone.Cache Purge** permission

### Magento

[](#magento)

RequirementVersionPHP`^8.1`Magento 2 / `magento/framework``~103.0`---

Installation
------------

[](#installation)

1. Require the module via Composer:

    ```
    composer require studioraz/magento2-cloudflare
    ```
2. Enable the module and run setup:

    ```
    bin/magento module:enable SR_Cloudflare
    bin/magento setup:upgrade
    bin/magento setup:di:compile
    bin/magento cache:clean
    ```

---

Configuration
-------------

[](#configuration)

All settings are available in the Magento Admin under:

**Stores &gt; Configuration &gt; Studio Raz &gt; Cloudflare**

### General Settings (Image Optimization)

[](#general-settings-image-optimization)

FieldDefaultDescriptionEnabledNoEnable/disable Cloudflare image optimization for the store view.Image Quality`85`JPEG/WebP/AVIF quality (1--100).Image Fit`none`How image dimensions are interpreted. See [Cloudflare fit documentation](https://developers.cloudflare.com/images/image-resizing/url-format/#fit).**Image Fit options:**

ValueDescription`none`No fit constraint applied (parameter omitted).`contain`Scale down to fit within width x height, preserving aspect ratio.`cover`Resize to fill width x height, cropping if necessary.`crop`Crop to exact width x height.`pad`Resize to fit within bounds and pad remaining space.`scale-down`Like `contain`, but never scales up.### Cache (FPC) Settings

[](#cache-fpc-settings)

These settings are scoped to **Default / Website** (not Store View).

FieldDefaultDescriptionEnabledNoEnable Cloudflare FPC cache management.Zone ID--Cloudflare Zone ID from the dashboard Overview page.Account ID--Cloudflare Account ID from the dashboard Overview page.API Token--Cloudflare API Token with **Zone.Cache Purge** permission. Stored encrypted.DebugNoWhen enabled, logs API requests and responses to `var/log/srcloudflarecache.log`.[![Screenshot 2026-04-01 at 23 53 08](https://private-user-images.githubusercontent.com/51929620/572776995-f9df2e3f-adbb-43f2-b2b7-c5536f57d79f.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXV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MjAyNjA2MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNjE4VDEyMjg1NFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTAyY2IwYzVjMGFkM2MxMjY3OGYzZGMwY2Y1ZDBlNDI2YTE4YjM5ZTIwNGVkMWJhM2Q5YzNiODg2NGJmN2UzNGImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRnBuZyJ9.WWsG1ngGVvoi95gTGvmDgI0LvHEdBE6dYlrS2wB3Ync)> **Important:** You must also select Cloudflare as the FPC application. Go to **Stores &gt; Configuration &gt; Advanced &gt; System &gt; Full Page Cache &gt; Caching Application** and select **Cloudflare**.

How It Works
------------

[](#how-it-works)

### Full-Page Cache Flow

[](#full-page-cache-flow)

When Cloudflare is selected as the caching application, the module adds cache tags to every page response. A Cloudflare Worker (deployed on your Cloudflare account) intercepts incoming requests before they reach your server and handles caching decisions at the edge -- just like Varnish would, but without any server-side infrastructure.

```
Browser ──> Cloudflare CDN ──> Worker (cache check) ──> Origin (Magento)
                                                      **Note:** Even a "full" flush only purges cached pages for your site. It preserves the Cloudflare Image Transformations cache, so your optimized images remain available without re-processing.

---

Image Optimization
------------------

[](#image-optimization-1)

When image optimization is enabled (**General &gt; Enabled = Yes**), the module rewrites image URLs from their standard Magento paths to the Cloudflare image transformations endpoint:

```
https://example.com/cdn-cgi/image/format=auto,metadata=none,quality=85,width=300,height=300/media/catalog/product/image.jpg

```

### Supported image types

[](#supported-image-types)

- Product catalog images (thumbnails, listings, gallery)
- Product media gallery URLs
- CMS page and block images
- Store logo
- Widget images
- Mirasvit catalog label badges (if [Mirasvit CatalogLabel](https://mirasvit.com/) is installed)

When enabled, Magento's local image cache generation is skipped entirely. Images are served directly from Cloudflare, eliminating the `/pub/media/catalog/product/cache/` directory and reducing disk usage.

---

Troubleshooting
---------------

[](#troubleshooting)

**Images are not being resized / URLs are not rewritten**

- Ensure **General &gt; Enabled** is set to **Yes** for the applicable scope (Store View).
- Check that your Cloudflare zone has [Image Transformations](https://developers.cloudflare.com/images/) enabled.
- Verify the image URL contains `/cdn-cgi/image/` -- if it does not, check whether another plugin or cache is serving a stale URL.

**Cache is not being purged after product/category save**

- Ensure **Cache &gt; Enabled** is set to **Yes**.
- Ensure **Zone ID** and **API Token** are correctly set and that the API Token has **Zone.Cache Purge** permission.
- Confirm that Cloudflare is selected as the caching application in **Stores &gt; Configuration &gt; Advanced &gt; System &gt; Full Page Cache &gt; Caching Application**.
- Enable **Cache &gt; Debug** and inspect `var/log/srcloudflarecache.log` for API errors.

**Pages are always served from origin (no CDN HIT)**

- Confirm the Cloudflare Worker is deployed and routed to your domain.
- Check that `Cache-Tag` headers are present in origin responses (visible in browser DevTools or `curl -I`).
- Ensure the worker's `ADMIN_PATH` variable matches your actual admin path if it is customized.
- Check `X-FPC-*` headers in the response (requires `DEBUG=true` in worker env).

[![Screenshot 2026-04-01 at 23 09 18](https://private-user-images.githubusercontent.com/51929620/572782924-2fec62e5-982a-4ee1-87a3-0c653a7c7cb6.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODE3ODYwMzQsIm5iZiI6MTc4MTc4NTczNCwicGF0aCI6Ii81MTkyOTYyMC81NzI3ODI5MjQtMmZlYzYyZTUtOTgyYS00ZWUxLTg3YTMtMGM2NTNhN2M3Y2I2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA2MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlP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headers missing**

- Set the `DEBUG` environment variable to `true` directly in the Cloudflare Worker settings.

**Images are served in original format instead of WebP/AVIF**

- Verify that your Cloudflare zone has [Image Transformations](https://developers.cloudflare.com/images/) enabled.
- Check the browser's `Accept` header includes `image/webp` or `image/avif`.
- Confirm the image URL uses the `/cdn-cgi/image/format=auto,...` format -- the `format=auto` parameter is what enables format negotiation.

---

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit issues and pull requests.

1. Fork the repository
2. Create your feature branch (`git checkout -b (feature/bugfix)/my-feature`)
3. Commit your changes
4. Push to the branch (`git push origin feature/my-feature`)
5. Open a Pull Request

Please follow the [Magento 2 coding standards](https://developer.adobe.com/commerce/php/coding-standards/).

---

License
-------

[](#license)

This project is licensed under the [MIT License](LICENSE).

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance92

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~102 days

Recently: every ~15 days

Total

14

Last Release

41d ago

Major Versions

0.0.1 → 1.0.02022-10-11

PHP version history (3 changes)0.0.1PHP ~7.4

1.2.1PHP ~7.4|^8.0

1.6.3PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/4bfa52434a9977959b38e23769e70eedf6ceeade2d12daf7ee1f243b46b47ce7?d=identicon)[itaymesh](/maintainers/itaymesh)

---

Top Contributors

[![d10nZ](https://avatars.githubusercontent.com/u/9153335?v=4)](https://github.com/d10nZ "d10nZ (12 commits)")[![dm-vasylenko](https://avatars.githubusercontent.com/u/51929620?v=4)](https://github.com/dm-vasylenko "dm-vasylenko (10 commits)")[![itaymesh](https://avatars.githubusercontent.com/u/493197?v=4)](https://github.com/itaymesh "itaymesh (6 commits)")[![MaximSR](https://avatars.githubusercontent.com/u/42231590?v=4)](https://github.com/MaximSR "MaximSR (3 commits)")[![github-studioraz](https://avatars.githubusercontent.com/u/22908864?v=4)](https://github.com/github-studioraz "github-studioraz (2 commits)")[![MaxMage](https://avatars.githubusercontent.com/u/35223992?v=4)](https://github.com/MaxMage "MaxMage (2 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (1 commits)")

### Embed Badge

![Health badge](/badges/studioraz-magento2-cloudflare/health.svg)

```
[![Health](https://phpackages.com/badges/studioraz-magento2-cloudflare/health.svg)](https://phpackages.com/packages/studioraz-magento2-cloudflare)
```

###  Alternatives

[elgentos/regenerate-catalog-urls

Regenerate Catalog URL Rewrites (products, categories, cms pages)

2842.6M](/packages/elgentos-regenerate-catalog-urls)[nosto/module-nostotagging

Increase your conversion rate and average order value by delivering your customers personalized product recommendations throughout their shopping journey.

27703.7k4](/packages/nosto-module-nostotagging)[tig/postnl-magento2

TIG Magento 2 PostNL extension

59570.5k5](/packages/tig-postnl-magento2)[myparcelnl/magento

A Magento 2 module that creates MyParcel labels

1860.2k](/packages/myparcelnl-magento)[loki/magento2-components

Core module for defining Alpine.js components with advanced AJAX features

1011.8k23](/packages/loki-magento2-components)[angeo/module-llms-txt

Magento 2 module for AI Engine Optimization (AEO). Generates spec-compliant llms.txt and llms-full.txt per llmstxt.org standard, plus streaming JSONL for vector indexing. Multi-store, multi-website, CLI, cron, async admin UI, Page Builder-aware sanitization, customer-group pricing, atomic writes, ETag/Cache-Control, .md mirrors.

111.1k](/packages/angeo-module-llms-txt)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
