CDN with Regional Points of Presence
CDN (Content Delivery Network) caches static resources on servers worldwide. User in Vladivostok gets image from server in Novosibirsk or Tokyo — not from Moscow. TTFB difference — hundreds of milliseconds.
Choosing CDN Provider
| Provider | PoP in CIS | Features |
|---|---|---|
| Cloudflare | Moscow, Kyiv, Almaty | Free basic plan, WAF |
| Gcore | 10+ points in CIS | Best Russia coverage |
| AWS CloudFront | Moscow | S3 integration, Lambda@Edge |
| Bunny CDN | Moscow | Cheap, simple |
| VK Cloud CDN | CIS | For Russian traffic |
Cloudflare CDN Setup
After connecting domain to Cloudflare, set up caching:
Page Rules for static:
URL: *.example.com/assets/*
Cache Level: Cache Everything
Edge Cache TTL: 1 month
Browser Cache TTL: 1 week
Cloudflare Cache Rules (new interface):
Field: URI Path
Operator: starts with
Value: /assets/
Action: Cache eligibility → Eligible for cache
Cache TTL: 30 days
AWS CloudFront Setup
{
"Origins": [{
"DomainName": "example.com",
"Id": "origin-1",
"CustomOriginConfig": {
"HTTPSPort": 443,
"OriginProtocolPolicy": "https-only"
}
}],
"DefaultCacheBehavior": {
"TargetOriginId": "origin-1",
"ViewerProtocolPolicy": "redirect-to-https",
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6"
},
"CacheBehaviors": [{
"PathPattern": "/assets/*",
"TargetOriginId": "origin-1",
"CachePolicyId": "CACHING_OPTIMIZED_POLICY_ID",
"Compress": true
}]
}
Proper Cache Headers on Server
CDN respects origin server headers. Nginx config:
location ~* \.(js|css|woff2|png|jpg|webp|svg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
add_header Vary "Accept-Encoding";
}
location ~* \.html$ {
expires 1h;
add_header Cache-Control "public, must-revalidate";
}
immutable tells browser: don't do conditional request even on page reload. Works with content-hashed filenames (app.a1b2c3.js).
Cache Invalidation
On new code deployment invalidate CDN cache:
# Cloudflare
curl -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/purge_cache" \
-H "Authorization: Bearer $CF_TOKEN" \
-d '{"purge_everything":true}'
# AWS CloudFront
aws cloudfront create-invalidation \
--distribution-id $DIST_ID \
--paths "/assets/*"
In CI/CD pipeline invalidation runs automatically after deploy.
Timeline
CDN setup with caching configuration and auto-invalidation on deploy: 1–2 working days.







