> ## Documentation Index
> Fetch the complete documentation index at: https://spreecommerce.org/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# CDN

> Learn how to improve performance of your Spree application by using a CDN (Content Delivery Network).

To improve performance of your Spree application, we recommend using a CDN (Content Delivery Network) to cache images and static files.

We recommend using [Cloudflare](https://www.cloudflare.com/) as your CDN provider. It's free and simple to set up.

After setting up your Cloudflare account and adding your domain name to Cloudflare, you will need to set your cache settings.

Go to your domain name in Cloudflare and click on "Caching" tab and select "Cache Rules".

<img src="https://mintcdn.com/spreecommerce/OgdQHBPQ0RbaKyDN/images/developer/deployment/cloudflare_caching.png?fit=max&auto=format&n=OgdQHBPQ0RbaKyDN&q=85&s=fad8fc747a5d83487ae5364e7e2e8261" alt="Cloudflare Cache Rules" width="510" height="382" data-path="images/developer/deployment/cloudflare_caching.png" />

Click on "Create Rule" and set up the rule as below:

<img src="https://mintcdn.com/spreecommerce/OgdQHBPQ0RbaKyDN/images/developer/deployment/cloudflare_cache_rule_1.png?fit=max&auto=format&n=OgdQHBPQ0RbaKyDN&q=85&s=9293f7d03f5c003008f168b7a17d59a4" alt="Cloudflare Cache Rule Settings" width="2110" height="1368" data-path="images/developer/deployment/cloudflare_cache_rule_1.png" />

Supply the first value with

```url theme={"theme":"night-owl"}
/rails/active_storage/representations/
```

and the second value with

```url theme={"theme":"night-owl"}
/assets
```

This will handle caching of both images and static files such as JavaScript and CSS files.

Now scroll down and set the settings as below:

<img src="https://mintcdn.com/spreecommerce/II6sKnqAuUp3_6IP/images/developer/deployment/cloudflare_cache_rule_2.png?fit=max&auto=format&n=II6sKnqAuUp3_6IP&q=85&s=65a41fb65c6af06e8154ed85a78e2b07" alt="Cloudflare Cache Rule Settings" width="2136" height="1778" data-path="images/developer/deployment/cloudflare_cache_rule_2.png" />

Finally, click on "Deploy" and you are done!

## Dedicated CDN Host

The setup above caches on your primary domain and needs no extra configuration. If you instead serve assets and images from a separate CDN hostname (e.g. a CloudFront or Fastly distribution at `cdn.example.com` with your app as the origin), set the `CDN_HOST` environment variable:

```bash theme={"theme":"night-owl"}
CDN_HOST=cdn.example.com
```

Static asset URLs and image/attachment URLs (including those in API responses) will then use this host instead of [`RAILS_HOST`](/docs/developer/deployment/environment_variables#urls-and-hosts). Host only, no protocol — URLs keep the scheme of your primary host.
