Build an effective content delivery strategy for e-commerce sites using CDNs, edge caching, image optimization, and cache invalidation to improve global page load times.
Introduction
Page speed directly impacts e-commerce revenue. Studies consistently show that every 100ms of additional latency costs 1 percent in conversions. For a store doing $10 million annually, that is $100,000 lost per 100ms of delay. A well-designed content delivery strategy ensures that shoppers worldwide experience fast page loads regardless of their geographic location.
This guide covers CDN architecture, edge caching policies, image optimization, and cache invalidation strategies tailored for e-commerce workloads.
CDN Architecture for E-Commerce
A content delivery network places cached copies of your assets at edge locations worldwide. For e-commerce, the CDN should handle:
- Static assets: CSS, JavaScript, fonts, and media files
- Product images: The largest payload on most product pages
- Full-page cache: Entire HTML responses for anonymous visitors
User → CDN Edge (cache hit) → Response in 20-50ms
User → CDN Edge (cache miss) → Origin server → 200-500ms
Popular options include CloudFront, Cloudflare, and Fastly. Each offers different cache control mechanisms and edge compute capabilities.
Cache Headers and Policies
Configure your origin server to send appropriate cache headers:
# Static assets - cache aggressively
location ~* \.(css|js|woff2|png|jpg|webp|avif|svg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
add_header Vary "Accept-Encoding";
}
# Product pages for anonymous users
location /products/ {
add_header Cache-Control "public, s-maxage=3600, stale-while-revalidate=86400";
add_header Vary "Cookie";
}
# Cart and checkout - never cache
location ~* /(cart|checkout|customer)/ {
add_header Cache-Control "private, no-store";
}
The stale-while-revalidate directive is particularly valuable for e-commerce. It serves a stale cached page instantly while fetching a fresh version in the background, ensuring users never wait for cache misses.
Image Optimization Pipeline
Product images typically account for 60-80 percent of page weight. Implement an automated optimization pipeline:
# Convert images to WebP and AVIF at multiple sizes
for img in /var/www/media/catalog/product/*.jpg; do
cwebp -q 80 "$img" -o "${img%.jpg}.webp"
avifenc --min 20 --max 40 "$img" "${img%.jpg}.avif"
done
Serve the optimal format using content negotiation:
map $http_accept $webp_suffix {
default "";
"~*webp" ".webp";
}
location /media/catalog/ {
try_files $uri$webp_suffix $uri =404;
}
Cache Invalidation Strategy
Stale product data - wrong prices, out-of-stock items showing as available - damages customer trust. Implement targeted cache invalidation:
- Price changes: Purge individual product page URLs via CDN API
- Stock updates: Use short TTLs (5-10 minutes) for inventory-sensitive pages
- Catalog-wide changes: Purge by cache tag or surrogate key if your CDN supports it
# CloudFront invalidation for specific products
aws cloudfront create-invalidation \
--distribution-id E1ABCDEF123 \
--paths "/products/blue-widget" "/products/red-widget"
Measuring Impact
Track these metrics before and after implementing your CDN strategy:
- Cache hit ratio: Target above 90 percent for static assets
- Global TTFB: Measure from multiple regions using synthetic monitoring
- LCP (Largest Contentful Paint): Should be under 2.5 seconds globally
- Origin offload: Percentage of requests served from cache without hitting origin
For rendering strategy decisions that complement CDN caching, see our guide on Next.js ISR vs SSR. Our architecture planning service includes full CDN and content delivery audits for e-commerce platforms.
A robust content delivery strategy is not optional for e-commerce - it is a revenue driver. Combine aggressive CDN caching, automated image optimization, and smart cache invalidation to deliver fast experiences to customers worldwide while keeping origin server load manageable.
Or read how we handle it in Architecture & Planning.
Related Articles
Magento 2 EU-Compliant Invoice PDF with Translations
Magento 2 does not print the invoice date on PDF invoices or translate them per store view. Our PdfOverride module adds EU-compliant invoice dates and automatic store-based translations.
MagentoHow to Set Up Redis and Valkey Caching for Magento 2
Adobe no longer supports Redis cache on Magento 2.4.9 or later patch releases, so the first decision is Redis or Valkey, not how to configure Redis. This guide covers both: the exact version cutoffs, the licence history behind the split, CLI configuration for cache and sessions, why sessions need their own instance with noeviction, memory sizing, and the two metrics that tell you whether the cache is actually working.
CloudWhy So Many Node Apps Still Run on EC2 and PM2, and When It Is Time for ECS or EKS
A huge share of the web still runs on a handful of EC2 instances with Node.js under PM2 behind a load balancer. It is not a foolish setup, but it quietly becomes a liability: unpatched OS and runtime, snowflake servers, risky manual deploys, and resilience that is more oversold than real. Here is why teams stay on it for years, when it is genuinely fine to leave it, and when it is time to move to ECS or EKS.