In the competitive world of e-commerce, speed is currency. Every millisecond counts when it comes to conversion rates, bounce rates, and search engine rankings. For Shopware merchants, leveraging a Content Delivery Network (CDN) is one of the most impactful steps to optimize performance. With the release of Shopware 6.7, the platform has refined its asset handling mechanisms, making CDN configuration more robust yet requiring precise setup to unlock full potential.

This guide dives deep into configuring CDNs in Shopware 6.7, covering best practices, configuration parameters, and critical nuances for media and theme delivery.

Why Configure a CDN in Shopware 6.7?

A CDN distributes your static assets across geographically dispersed servers. When a customer visits your store, they download images, CSS, and JavaScript from the nearest node rather than your origin server. In Shopware 6.7, this is achieved by rewriting URLs for static resources to point to your CDN base URL.

Key benefits include:

  • Reduced Latency: Faster load times for global audiences.
  • Offloaded Server Load: Your origin server handles dynamic requests (cart, checkout) while the CDN serves heavy media.
  • Improved Core Web Vitals: Critical metrics like LCP and FID benefit significantly from accelerated asset delivery.

Shopware 6.7 Asset Architecture Basics

Before configuring your CDN, understand what gets served. Shopware 6.7 manages two primary groups of static assets:

  1. Storefront Assets: JavaScript bundles, CSS files, and fonts located in public/js/ and public/css/.
  2. Media & Theme Assets: Customer uploads, product images, thumbnails, and compiled theme resources found in public/media/, public/thumbnail/, and public/theme/.

Configuring the CDN allows you to unify these under a single domain or manage them separately based on your infrastructure needs.

Step 1: Prepare Your CDN Provider

Most modern CDN providers (Cloudflare, AWS CloudFront, Fastly) work seamlessly with Shopware. Ensure your CDN origin points to your Shopware public directory. Since Shopware rewrites URLs based on configuration, the CDN simply acts as a cache layer for whatever base path Shopware requests.

Pro Tip: Configure your CDN cache rules to ignore query strings for HTML but cache static files aggressively. Ensure your origin does not return Cache-Control: private for media assets if you want them cached globally.

Step 2: Configure CDN in Shopware 6.7

In Shopware 6.7, the recommended approach is using environment variables. This ensures consistency across deployment environments and keeps configuration out of version control.

Open your .env or .env.local file and set the following variable:

# .env.local

# Define your CDN base URL
SW_CDN_URL=https://cdn.yourstore.com

By setting SW_CDN_URL, Shopware automatically injects this base into asset URLs for both storefront bundles and media assets. This is the cleanest method supported in 6.7 and later versions, leveraging Symfony's environment variable injection for zero-runtime configuration overhead.

Advanced Configuration via Parameters

If you need granular control, such as a different path structure or multiple CDN endpoints, you can override parameters in config/services.yaml. However, note that environment variables generally take precedence in Shopware's dependency injection container.

# config/services.yaml

parameters:
    # Fallback if SW_CDN_URL is not set
    shopware.assets.cdn.url: 'https://assets.yourstore.com'
    
    # Optional: Define a custom path prefix within the CDN
    shopware.assets.cdn.path: '/shopware/6.7/static'

Handling Multiple Asset Groups

Sometimes, you may want to route media assets to a high-throughput CDN while keeping theme assets on a standard CDN. Shopware 6.7 allows splitting configuration via specific parameters:

# config/services.yaml

parameters:
    shopware.assets.cdn.url: 'https://cdn-main.com'
    
    # Media specific override (if required by your setup)
    shopware.media.cdn.url: 'https://media-highperf.com'

Note: The shopware.media.cdn.url parameter provides isolation for media delivery, which is useful if you have massive storage requirements that differ from your storefront traffic patterns.

Step 3: Deploy and Validate Changes

After updating configurations, Shopware requires a cache clear to pick up new URLs. In Shopware 6.7, this must be done carefully in production environments.

Run the following commands:

bin/console system:write-installed-data --all
bin/console cache:clear
bin/console theme:compile --all
bin/console asset:install public

Critical Warning: Never run bin/console cache:clear on a live production site without maintenance mode enabled. It will take your store offline momentarily while the cache rebuilds. Use the administration panel or a rolling deployment strategy with --maintenance-mode flags where applicable.

Step 4: Managing CDN Cache Invalidation

One of the most common pain points in Shopware setups is stale content. When you update a theme or upload new product images, your CDN may continue serving old versions if not configured correctly.

Shopware does not automatically purge external CDNs. You must implement a strategy:

  1. TTL Management: Set reasonable Time-To-Live (TTL) values on your CDN. For media assets, a longer TTL is safe due to content versioning. Shopware appends hashes or version IDs to filenames, making aggressive caching safe for static files.
  2. Webhooks: Integrate your CDN provider's purge API with a Shopware workflow or custom plugin that triggers on media_deleted or theme_published events.
  3. Versioned Paths: Ensure your CDN treats versioned URLs as unique resources.

Best Practices for Shopware 6.7 and Beyond

  • HTTPS is Mandatory: Ensure your CDN URL uses HTTPS. Mixed content warnings will break the store experience.
  • Test Asset URLs: Inspect your page source. Product images should look like https://cdn.yourstore.com/media/image/abc123.jpg, not https://yourshop.de/media/image/abc123.jpg.
  • Leverage Service Worker: Shopware 6.7 enhances client-side caching strategies. Ensure your CDN headers support HTTP/2 or HTTP/3 for multiplexed requests.
  • Monitor Performance: Use tools like GTmetrix or WebPageTest post-configuration to verify that assets are being served from the edge and latency has decreased.

Conclusion

Configuring a CDN in Shopware 6.7 is straightforward thanks to the unified SW_CDN_URL environment variable approach. By directing static traffic away from your origin server and utilizing global edge networks, you significantly enhance store performance and reliability.

Remember that configuration is only half the battle; consistent cache management and proper deployment workflows ensure that speed gains persist even during updates. Take control of your storefront's velocity today by implementing these CDN best practices in your Shopware 6.7 ecosystem.