Kokil Thapa - Professional Web Developer in Nepal
Freelancer Web Developer in Nepal with 15+ Years of Experience

Kokil Thapa is an experienced full-stack web developer focused on building fast, secure, and scalable web applications. He helps businesses and individuals create SEO-friendly, user-focused digital platforms designed for long-term growth.

CDN Fundamentals: How Content Delivery Works

By Kokil Thapa | Last reviewed: September 2026

Your origin server in Kathmandu can serve a page in 200 ms locally. A visitor in Doha or Sydney may wait two seconds for the same HTML, CSS, and images. CDN Fundamentals: How Content Delivery Works starts with that gap. A content delivery network copies cacheable assets to edge points of presence (PoPs) worldwide. Users fetch files from the nearest healthy node instead of your single server. On production web applications in Nepal and abroad, that shift often cuts Time to First Byte and improves Core Web Vitals without rewriting application code.

What is a CDN and why does CDN content delivery matter?

A content delivery network is a distributed system of edge servers operated by a provider such as Cloudflare, AWS CloudFront, Fastly, or BunnyCDN. Each PoP sits on high-bandwidth networks close to end users. The provider handles TLS termination, HTTP/2 or HTTP/3, compression, and routing logic at the edge.

The origin remains your VPS, shared host, or cloud instance running Laravel, WordPress, or Magento. The CDN sits in front as a reverse proxy and cache layer. Most traffic for images, CSS, JavaScript, fonts, and PDFs never touches origin after the first fetch.

I've seen this pattern on international eCommerce builds like florist shops serving Gulf and South Asian markets. Product images and theme assets dominate page weight. Serving them from Singapore or Mumbai PoPs beats routing every byte through a single origin in Nepal or Europe.

CDN Architecture OverviewUser AKathmanduUser BDubaiEdge PoPMumbaiEdge PoPSingaporeOriginLaravel / WPUbuntu + PHPcache misscache hit
CDN fundamentals: users request assets from nearby edge PoPs; only cache misses reach your origin server.

Benefits extend beyond speed. A CDN absorbs traffic spikes during Dashain sales or a viral blog post. DDoS mitigation and WAF rules often ship with the same provider. For technical SEO, faster LCP and stable TTFB correlate with better crawl efficiency and user retention.

How does CDN content delivery work step by step?

Understanding the request path prevents misconfigured caches and mysterious stale files. Every CDN interaction follows the same logical sequence.

  1. DNS resolution. Your domain's CNAME or ANAME points cdn.example.com or the apex domain to the provider. See how DNS works for the full chain from resolver to authoritative nameserver.
  2. Edge routing. Anycast or geo-DNS sends the client to the closest healthy PoP. Latency-based routing picks among several nodes in the same region.
  3. Cache lookup. The edge checks its local store for the URL key, query string rules, and Vary headers.
  4. Cache hit. If a fresh object exists, the edge returns it with low latency. No origin round trip occurs.
  5. Cache miss. The edge fetches from origin, stores the response per cache rules, then serves the client.
  6. Revalidation. On stale objects, the edge may send conditional requests with If-None-Match or If-Modified-Since. A 304 response saves bandwidth.
CDN Request FlowBrowserEdge PoPCache StoreTTL checkOriginCache HITFast 200Cache MISSFetch origin1. GET2. Lookup3a. Serve3b. Miss4. Store
How content delivery works: every request hits the edge first; origin traffic drops sharply after warm cache.

Pull vs push CDNs

Most modern CDNs use a pull model. The edge fetches on first request. You change DNS or CNAME and assets propagate lazily. A push model uploads files to storage the CDN controls. Live streaming and large software downloads sometimes use push. For typical Laravel or WordPress sites, pull is simpler and cheaper.

Anycast and health checks

Providers advertise the same IP block from many locations. BGP routes packets to the nearest PoP. Health probes remove failed nodes from rotation. If Mumbai goes dark, traffic shifts to Singapore without DNS changes.

What content belongs on a CDN versus the origin?

Not every byte should be cached at the edge. Match asset type to TTL and cache key rules.

Asset typeCDN fitTypical TTLNotes
Images, CSS, JS, fontsExcellent7–365 daysUse fingerprinted filenames from Vite or Mix
Public PDFs, videosExcellent1–30 daysLarge files benefit most from edge bandwidth
HTML pages (marketing)Good with careMinutes to hoursRespect cookies and Cache-Control: private
Authenticated dashboardsPoorDo not cacheBypass cache for session cookies
API JSON responsesCase by case0–60 secondsOnly idempotent GET with explicit headers
Cart, checkout, webhooksNever0Always origin-direct

On a legal-tech portal I built, public guide pages cache well. Client document areas must never hit shared edge cache. Cookie-based cache bypass rules are non-negotiable there.

WooCommerce and custom Laravel carts need the same split. Static product media on the CDN; checkout and account routes excluded via page rules or cache keys. Our eCommerce development practice treats that boundary as a launch checklist item.

Cache Hit vs Cache MissCache HITUser to edge: ~20 msEdge serves objectTotal: ~30-80 msOrigin load: zeroBandwidth: edge onlyCache MISSUser to edge: ~20 msEdge to origin: ~200 msTotal: ~250-600 msOrigin load: one fetchNext user: HITwarm
CDN fundamentals in practice: cache hits keep latency low; misses warm the edge for the next visitor.

How do you set cache headers and CDN rules correctly?

The CDN honours HTTP caching semantics defined in MDN's HTTP caching guide and RFC 9111. Your origin must send intentional headers. Defaults from Apache or nginx often cache too much or too little.

Essential response headers

  • Cache-Control: public, max-age=31536000, immutable for versioned assets.
  • Cache-Control: public, max-age=3600, s-maxage=86400 for HTML where the CDN may hold longer than browsers.
  • Cache-Control: private, no-store for authenticated responses.
  • ETag and Last-Modified for efficient revalidation.
  • Vary: Accept-Encoding when gzip and Brotli variants exist.

Apache example for static assets

<FilesMatch "\.(css|js|jpg|jpeg|png|webp|woff2)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>

<FilesMatch "\.(html|php)$">
    Header set Cache-Control "public, max-age=0, must-revalidate"
</FilesMatch>

Laravel middleware for API fragments

public function handle(Request $request, Closure $next)
{
    $response = $next($request);

    if ($request->isMethod('GET') && $response->isSuccessful()) {
        $response->headers->set(
            'Cache-Control',
            'public, max-age=60, s-maxage=300'
        );
    }

    return $response;
}

Laravel 13 on PHP 8.3+ pairs well with Vite 8.x fingerprinted builds. Filenames like app-B2k9f.js allow aggressive immutable caching. Details for CloudFront and Laravel appear in our AWS CloudFront CDN setup guide. Cloudflare-specific page rules are covered in the Cloudflare CDN setup article.

Purge and invalidation

When you deploy without fingerprinted assets, you must purge CDN cache. Methods include API purge by URL, tag, or prefix. On Deployer releases I purge /build/* after symlink swap. Forgetting purge after a hotfix is a common source of "I deployed but users still see the old JS."

Which CDN setup fits Nepal-based and global projects in 2026?

Provider choice depends on traffic geography, budget, and stack. Nepal-origin sites often mix local hosting with a global CDN front door.

ProviderStrengthsTypical costGood for
Cloudflare (free/pro)DNS, WAF, DDoS, easy SSLRs 0–2,500/mo (~USD 0–19)WordPress, SMB, legal portals
AWS CloudFrontS3 origin, Lambda@EdgePay per GB egressLaravel on EC2, API-heavy apps
BunnyCDNLow cost, simple pull zonesRs 800+/mo (~USD 6+)Media-heavy eCommerce
FastlyInstant purge, edge computeHigher, enterpriseNews, high-churn content

For many Nepal SMB sites, Cloudflare's free tier plus Let's Encrypt on origin covers 80% of needs. That aligns with advice in why Nepali businesses should use a CDN. Enterprise Laravel apps on AWS often standardise on CloudFront with an S3 bucket for compiled assets.

CDN Setup Decision PathNew site launch?WordPress /WooCommerceLaravel + ViteGlobal videoCloudflareorange cloud DNSCloudFrontS3 asset originBunnyCDNpull zoneAlways exclude checkout, admin, and webhook paths
Choosing how content delivery works for your stack: match CDN provider to CMS, framework, and media profile.

Domain and hosting setup should plan CDN DNS before go-live. Moving apex domains later adds downtime risk. I register the domain, point nameservers to the CDN when applicable, and keep origin IP restricted to provider IP ranges where possible.

What production mistakes break CDN caching?

These issues appear repeatedly on client audits and post-launch support calls.

  • Query string cache busting without CDN rule. style.css?v=2 creates a new cache key. Configure the CDN to ignore benign query params or use filename hashing instead.
  • Setting cookies on static assets. Some analytics scripts set cookies on every path. Set-Cookie on CSS breaks cache at many providers.
  • HTTPS mixed content. Page loads over CDN SSL but assets call http:// origin URLs. Browsers block or bypass cache.
  • Over-aggressive HTML caching. Logged-in users see another user's cached page. Use Cache-Control: private or bypass rules for cookies like wordpress_logged_in.
  • Forgetting origin firewall. Origin exposed to the open internet receives direct traffic and attacks. Allow only CDN egress IPs.
  • Stale opcache after deploy without purge. PHP opcache and CDN edge cache are separate layers. Reload PHP-FPM and purge CDN after releases.

Our testing and optimization service includes cache verification with curl -I from multiple regions. A single browser test from your desk hides edge behaviour.

curl -sI https://cdn.example.com/build/app.css | grep -i cache-control
curl -sI https://cdn.example.com/build/app.css | grep -i x-cache

The X-Cache: HIT or CF-Cache-Status: HIT response header confirms edge delivery. Miss headers after repeated requests point to misconfigured TTL or bypass rules.

Redis 8.10 at origin handles application cache separately from CDN edge cache. Do not conflate them. Laravel php artisan config:cache affects server-side config. CDN purge does not flush Redis sessions or query cache.

For performance budgets, pair CDN work with image compression and lazy loading. A fast edge cannot fix unoptimised 2 MB hero images. Speed optimization treats CDN as one layer in a full stack review.

On travel booking sites, itinerary PDFs and gallery images moved to a pull zone cut origin egress bills noticeably. The booking engine itself stayed origin-direct with no cache. That split is the pattern to copy.

Security headers like Strict-Transport-Security and Content-Security-Policy should be set at origin or edge consistently. Cloudflare and CloudFront both support transform rules. Document your chosen layer so the next developer does not duplicate or conflict headers.

If you serve Nepali Unicode content, encoding must stay UTF-8 end to end. A mismatched charset header causes garbled text that caching preserves for hours. Our Nepali Unicode converter helps validate text before publish, but the CDN will faithfully cache whatever origin returns.

Official provider docs remain the source of truth for limits and API quotas. See Cloudflare Cache documentation and Amazon CloudFront Developer Guide for purge APIs, tiered cache, and origin shield options.

Key Takeaways

  • A CDN caches assets at edge PoPs so users fetch content geographically close to them instead of always hitting your origin.
  • Cache hits return in tens of milliseconds; misses fetch origin once then warm the edge for subsequent requests.
  • Put images, CSS, JS, fonts, and public downloads on the CDN; keep checkout, admin, and authenticated routes uncached.
  • Send explicit Cache-Control headers and use fingerprinted asset names from Vite or Mix for long TTLs.
  • Purge CDN cache after deploys that change non-fingerprinted files, and restrict origin access to provider IP ranges.
  • Match provider to stack: Cloudflare for SMB WordPress, CloudFront for AWS Laravel, BunnyCDN for media-heavy shops.

People Also Ask

Is a CDN the same as web hosting?

No. Hosting runs your application and database on an origin server. A CDN caches and delivers copies of static and cacheable responses from edge nodes. You still need hosting; the CDN sits in front as a performance and protection layer.

Does a CDN help SEO?

Yes, indirectly. Faster LCP, INP, and TTFB improve user experience signals and crawl budget efficiency. Google does not rank "CDN use" as a factor, but speed and availability affect outcomes. Pair CDN with sound content freshness strategy.

Can you use a CDN with a shared hosting plan?

Yes. Point your domain DNS to Cloudflare or similar and set the shared host as origin. Most pull CDNs work without root server access. You configure cache headers via .htaccess on Apache hosts common in Nepal.

What is origin shield?

Origin shield is an intermediate cache tier between regional PoPs and your server. Multiple edge misses collapse into one origin fetch. AWS CloudFront and some enterprise tiers offer it. It helps high-traffic sites reduce origin load during viral spikes.

Ship faster pages with CDN fundamentals applied correctly

CDN Fundamentals: How Content Delivery Works boils down to one idea: move bytes closer to users and cache aggressively where safe. DNS to edge, edge to origin on miss, purge on deploy, and never cache private sessions. On real projects—from legal information portals to cross-border eCommerce—that discipline delivers measurable speed without rewriting business logic.

If you want CDN wired into your Laravel, WordPress, or WooCommerce stack with correct headers, firewall rules, and deploy purge automation, review our support and maintenance offerings or browse the full project portfolio. Need hands-on help? Contact us to audit origin and edge configuration before your next launch.

Frequently Asked Questions

A CDN caches static and cacheable content on edge servers near users, so requests hit a nearby PoP instead of your origin on every fetch.

Cloudflare free or Pro costs Rs 0–2,500/month (~USD 0–19). BunnyCDN starts around Rs 800+/month (~USD 6+). AWS CloudFront charges pay-per-GB egress with no flat fee listed.

Yes, indirectly. Faster LCP, INP, and TTFB improve user experience and crawl efficiency. Google does not rank CDN use itself, but speed and availability affect outcomes.

DNS resolves your domain to the CDN provider via CNAME or ANAME. Anycast or geo-DNS routes the client to the closest healthy PoP. The edge checks its local store for a matching cache key including URL, query string rules, and Vary headers. On a cache hit, the edge returns the object immediately with no origin round trip. On a miss, the edge fetches from origin, stores the response per your cache rules, then serves the client. On stale objects, conditional requests with If-None-Match or If-Modified-Since may return a 304 and save bandwidth. After the first miss, subsequent visitors in that region get edge delivery.

Most modern CDNs use a pull model: the edge fetches content from your origin on the first request, then caches it for later visitors. You point DNS or CNAME at the provider and assets propagate lazily. Push CDNs require you to upload files to storage the CDN controls upfront. Pull is simpler and cheaper for typical Laravel or WordPress sites. Push suits live streaming and large software downloads where you preload big binaries before users request them. For florist eCommerce and legal portals I have worked on, pull zones cover images, CSS, and JS without manual upload workflows.

Images, CSS, JavaScript, fonts, and public PDFs or videos belong on the CDN with TTLs from one day to one year; use fingerprinted filenames from Vite or Mix for long immutable caching. Marketing HTML may cache for minutes to hours if you respect cookies and Cache-Control private. Authenticated dashboards, carts, checkout, and webhooks must always hit origin with zero TTL. API JSON GET responses are case by case—only idempotent reads with explicit headers, typically zero to sixty seconds. On legal-tech and WooCommerce projects I treat that split as a launch checklist: static media on CDN, session routes excluded via page rules or cache keys.

Your origin must send intentional HTTP headers because Apache or nginx defaults often cache too much or too little. Set Cache-Control public, max-age=31536000, immutable for versioned assets; use public, max-age=3600, s-maxage=86400 where the CDN may hold HTML longer than browsers; and private, no-store for authenticated responses. Include ETag and Last-Modified for revalidation and Vary Accept-Encoding when serving gzip and Brotli variants. On Apache, use FilesMatch blocks in htaccess. In Laravel, middleware can set public, max-age=60, s-maxage=300 on successful GET API fragments. Laravel 13 with Vite 8.x fingerprinted builds like app-B2k9f.js allow aggressive edge TTLs without purge on every deploy.

No. Web hosting runs your application, database, and origin server—whether that is a VPS, shared host, or cloud instance running Laravel, WordPress, or Magento. A CDN sits in front as a reverse proxy and cache layer, copying static and cacheable responses to edge points of presence worldwide. You still need hosting for dynamic logic, sessions, and uncacheable routes. The CDN absorbs bandwidth for images, CSS, JavaScript, and fonts so most of that traffic never touches origin after the first fetch. Think of hosting as the kitchen and the CDN as nearby pantries stocked with ready servings.

Yes. Point your domain DNS to Cloudflare or a similar provider and configure your shared host as the origin. Most pull CDNs work without root server access—you only need to update nameservers or CNAME records and set cache headers. On Apache shared hosts common in Nepal, cache rules go in htaccess using FilesMatch directives for css, js, jpg, and similar extensions. Cloudflare free tier plus Let's Encrypt on origin covers most SMB WordPress and legal portal needs without upgrading hosting plans. Verify behaviour with curl -I from outside your office; a browser test from Kathmandu alone hides edge routing to Mumbai or Singapore PoPs.

Match provider to traffic geography, budget, and stack. Cloudflare free or Pro (Rs 0–2,500/month, ~USD 0–19) suits WordPress SMB sites and legal portals with DNS, WAF, DDoS, and easy SSL. AWS CloudFront fits Laravel on EC2 or API-heavy apps with pay-per-GB egress and S3 origin support. BunnyCDN (Rs 800+/month, ~USD 6+) is strong for media-heavy eCommerce. Fastly targets enterprise news and high-churn content with instant purge and edge compute at higher cost. Nepal-origin sites often mix local hosting with a global CDN front door. Plan DNS before go-live; moving apex domains later adds downtime risk.

Common audit findings include query-string cache busting like style.css?v=2 without CDN rules to ignore benign params—use filename hashing instead. Set-Cookie headers on static assets from analytics scripts break edge cache at many providers. HTTPS pages loading http:// assets cause mixed content and cache bypass. Caching HTML for logged-in users exposes wrong sessions; bypass wordpress_logged_in and similar cookies. Leaving origin open to the internet invites direct hits, bypasses edge DDoS protection, and becomes an attack surface. Deploying without purging non-fingerprinted JS after symlink swap leaves users on stale bundles. PHP opcache reload and CDN purge are separate steps both required after releases.

Do not rely on a single browser test from your desk. Run curl -sI against your asset URL and inspect Cache-Control and edge status headers. Look for X-Cache HIT on some providers or CF-Cache-Status HIT on Cloudflare. Repeated requests should show hit after the first miss warms the edge. Miss headers after several requests point to misconfigured TTL, query string rules, or cookie bypass. Testing from multiple regions matters because Kathmandu latency hides routing to Mumbai or Singapore PoPs. Pair header checks with origin access logs: traffic should drop sharply once cache is warm.

Origin shield is an intermediate cache tier between regional edge PoPs and your origin server. When several edge nodes in a region miss simultaneously, shield collapses those fetches into one origin request instead of many parallel hits. AWS CloudFront offers origin shield, and some enterprise CDN tiers include similar logic. It helps high-traffic sites during viral spikes or Dashain sales when many users across one geography request the same uncached asset. For typical Nepal SMB WordPress sites on Cloudflare free tier, standard edge caching suffices. Consider shield when origin egress bills or CPU spikes remain high despite CDN enabled.

When deploys change non-fingerprinted assets, you must invalidate edge cache manually. Providers offer API purge by URL, tag, or prefix. On Deployer releases I purge paths like /build/* after symlink swap. Forgetting purge after a hotfix is a frequent cause of users seeing old JavaScript despite a successful deploy. Fingerprinted Vite 8.x or Mix builds avoid this for hashed filenames because each release creates a new cache key. Laravel php artisan config:cache affects server-side config only—CDN purge does not flush Redis 8.10 sessions or application query cache at origin. Treat CDN purge as part of your deploy checklist alongside PHP-FPM reload.

Restrict origin firewall to accept traffic only from your CDN provider egress IP ranges. An exposed origin receives direct hits, bypasses edge DDoS protection, and becomes an attack surface. TLS termination can happen at the edge while origin still uses Let's Encrypt. Set security headers like Strict-Transport-Security and Content-Security-Policy consistently at origin or edge—document which layer owns them so the next developer does not duplicate or conflict rules. Cloudflare and CloudFront both support transform rules for headers. For authenticated areas like client document portals, use cookie-based cache bypass and Cache-Control private so shared edge cache never stores session-specific HTML.

Share this article

0 Comments

Leave a comment

Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

Quick Contact Options
Choose how you want to connect me: