Web Caching: Concepts, Speed Optimization Details & SEO

What is caching in web systems? Learn how it works, common types, HTTP caching, CDN, Redis, and how to optimize page speed to improve SEO and conversions.

cachingperformancebackendCachingPerformanceSEOCDNRedisNginxCore Web VitalsTối ưu tốc độ
Cover image: Web Caching: Concepts, Speed Optimization Details & SEO
Avatar of Trung Vũ Hoàng

Trung Vũ Hoàng

Author

7/5/202610 min read

1. What is caching? Why it matters for modern websites

Have you ever felt frustrated when a website loads too slowly? In the era of digital experience, caching is a technique that temporarily stores data to serve users faster. As a result, your pages reduce response time, save server resources, and improve SEO.

1.1 Basic concept

Caching is the process of temporarily storing copies of data (HTML, CSS, JS, images, API response) across different layers such as the browser, CDN, reverse proxy, or in application memory. When users visit, the system returns data from the cache instead of rebuilding it from the origin, reducing latency.

1.2 Key benefits

  • Speed: reduces TTFB, speeds up rendering.

  • Cost: saves bandwidth, CPU, and I/O.

  • Stability: handles peak-hour traffic better.

  • SEO: improves Core Web Vitals, boosts rankings and CTR.

1.3 Impact on SEO and Core Web Vitals

Google recommends LCP < 2.5s and INP < 200ms to meet Core Web Vitals standards. According to Deloitte (2020), reducing mobile load time by 0.1s can increase conversions by up to 8% in retail. Smart caching helps you consistently hit these thresholds, especially for static and semi-static content.

Takeaway: Caching is a simple, high-ROI speed lever for any website.

2. How caching works in web systems

Caching revolves around three concepts: freshness, validation, and invalidation (refresh/evicting cache). The system decides whether to serve from cache or request the origin based on TTL and HTTP headers.

2.1 Freshness vs Validation

  • Freshness: Data that is still “fresh” (not past max-age) can be served immediately from cache.

  • Validation: When expired, the cache can quickly check with the origin using ETag or Last-Modified to get a 304 Not Modified instead of re-downloading the entire resource.

2.2 Cache key and Vary

A cache key identifies a cache record (e.g., method + host + path + query + headers). The Vary directive (e.g., Vary: Accept-Encoding, Authorization) helps create keys based on context such as language, device, or cookies. A well-designed key prevents cache bloat and improves hit ratio.

2.3 Cache layers

  • Browser cache: closest to the user, reduces bandwidth usage.

  • CDN/Edge cache: multiple PoPs, reduces geographic latency.

  • Reverse proxy (Nginx/Varnish): sits in front of the application, handles microcaching.

  • Application/Object cache (Redis/Memcached): stores objects and query results.

Takeaway: Caching at the right layer maximizes speed and reduces load.

3. Common cache types in the web stack

Each cache type serves a different purpose. The right combination delivers outsized results.

3.1 Client-side and Edge

  • Browser cache: Stores assets (CSS/JS/images). Controlled via Cache-Control and ETag.

  • Service Worker cache: For Progressive Web App and offline mode.

  • CDN cache: Edge serves static/semi-static content and supports cache rules.

3.2 Server-side

  • Reverse proxy cache (Nginx, Varnish): Microcaches dynamic HTML for 1–10s to absorb traffic spikes.

  • Application/Object cache (Redis, Memcached): Caches render results, fragment cache, sessions.

  • Database/query cache: Caches expensive query results.

  • Opcode cache (OPcache): Stores PHP bytecode to reduce parsing/compilation.

3.3 Quick comparison table

Cache type

Location

Advantages

Limitations

Use case

Browser

Client

Reduces bandwidth, faster reloads

Doesn’t help the first visit

Versioned static assets

CDN

Edge

Lower latency, offloads origin

Complex invalidation

Images, video, semi-static HTML

Reverse proxy

In front of the app

Microcaches dynamic content

Complex cookie handling

Landing pages, search

Redis/Memcached

App layer

Very fast (in-memory)

Key management, consistency

Fragments, queries, sessions

OPcache

Runtime

Reduces CPU usage

PHP-only

PHP CMS (WordPress)

Takeaway: There’s no “one-size-fits-all.” Combine multiple cache layers.

4. HTTP caching: Cache-Control, ETag, Expires

HTTP caching is the foundation that enables browsers, CDNs, and proxies to make caching decisions.

4.1 Core Cache-Control directives

  • max-age=seconds: freshness lifetime of a resource.

  • s-maxage: prioritized for shared cache (CDN/proxy).

  • public/private: allow caching in shared/private caches.

  • no-store: do not store; used for sensitive data.

  • must-revalidate, stale-while-revalidate, stale-if-error: strategies to balance speed and freshness.

4.2 ETag and Last-Modified

ETag is a content fingerprint. When the client sends If-None-Match, the server can return 304 if nothing changed. Last-Modified works with If-Modified-Since. Both mechanisms reduce bandwidth usage after max-age expires.

4.3 Example header configurations

  • Versioned static assets: Cache-Control: public, max-age=31536000, immutable

  • Dynamic HTML: Cache-Control: public, s-maxage=10, stale-while-revalidate=60

  • Sensitive data: Cache-Control: no-store

Takeaway: Correct HTTP headers are the baseline for any caching strategy.

5. Cache strategy: invalidation, patterns, and microcaching

The hardest part of caching is invalidation—when and how to purge/refresh cache while staying fast and correct.

5.1 Cache invalidation

  • TTL (time-to-live): simple and reliable, but can be briefly stale.

  • Explicit purge: purge by key or by tag (e.g., Surrogate-Key on a CDN).

  • Versioning: rename files (hash) so assets are always fresh.

5.2 Common patterns

  • Cache-aside: The app reads from cache; on a miss, it fetches from origin and writes back to cache.

  • Write-through: Writes to cache at the same time as writing to the DB.

  • Write-back: Writes to cache first, then flushes to DB later—fast but with a risk of data loss.

5.3 Microcaching dynamic content

For news sites, landing pages, or high-traffic product pages, you can microcache HTML for 1–10s in Nginx/Varnish. This absorbs bursts, significantly reduces TTFB, and keeps data fresh enough.

Takeaway: Combining TTL + tag-based purging helps balance speed and freshness.

6. Tools & platforms: Nginx, Varnish, Redis, Cloudflare

Several popular tools make caching easier and more effective to implement.

6.1 Reverse proxy

  • Nginx: stable, supports proxy_cache and fastcgi_cache.

  • Varnish: strong HTTP caching, flexible VCL, solid tag-based purging.

6.2 In-memory cache

  • Redis: supports data structures, pub/sub, TTL; commonly used for Object Cache.

  • Memcached: simple and extremely fast for key-value caching.

6.3 CDN/Edge

  • Cloudflare/Fastly/Akamai: HTML and API caching, image optimization, stale-while-revalidate, Workers/Compute@Edge.

  • Image CDN: resizing, WebP/AVIF on-the-fly.

For CMS platforms like WordPress, combining Redis Object Cache + reverse proxy + CDN is a “golden stack.”

Takeaway: Prioritize tools that fit your team and budget.

7. Measurement & optimization: hit ratio, TTFB, and Core Web Vitals

If you don’t measure, you can’t optimize. Set clear KPIs to understand how well caching is performing.

7.1 Metrics to track

  • Cache hit ratio (% of requests served from cache): target > 80% for assets, > 50% for semi-static HTML.

  • TTFB: target < 200–500ms depending on region.

  • Origin offload: reduce origin requests by > 60%.

  • LCP/INP/CLS: monitor via Field data (CrUX, RUM).

7.2 Measurement tools

  • Lighthouse, PageSpeed Insights: lab evaluation.

  • WebPageTest, GTmetrix: waterfall and TTFB analysis.

  • CDN Analytics: hit ratio, bandwidth saved.

  • APM (Datadog, New Relic) + Grafana/Prometheus: server and application observability.

7.3 Optimization process

  1. Audit headers and segment content types.

  2. Set cache policies for HTML, API, and assets.

  3. Test impact on SEO and functionality (login, cart).

  4. Roll out gradually and monitor hit ratio and errors.

  5. Tune TTL, keys, and tag-based purging.

Takeaway: Set numeric targets, review regularly, and iterate continuously.

8. Risks & best practices: stale content, stampedes, security, and SEO

Caching is powerful, but it must be handled carefully to avoid frustrating issues.

8.1 Common risks

  • Stale content: showing old data after an update.

  • Cache stampede: many requests simultaneously “punch through” the cache.

  • Cache poisoning: attackers inject malicious data into cache.

  • Data leaks: caching private data incorrectly (cookies, account pages).

8.2 Best practices to prevent issues

  • Use stale-while-revalidate and stale-if-error to reduce stampedes.

  • Separate public vs private; do not cache responses with Authorization.

  • Use safe cache keys, validate input, and enforce HTTPS.

  • Tag-based purging, asset versioning, and thorough testing for update scenarios.

8.3 SEO & content considerations

  • Caching improves Core Web Vitals, supporting overall SEO.

  • Ensure structured data and sitemap updates when content changes.

  • Avoid accidentally caching noindex pages or user-personalized content.

Takeaway: Security and correctness are KPIs alongside speed.

9. Vietnam case study: an SME boosts conversions with caching

An anonymous retail SME runs a WordPress website with about 300K visits/month, often overloading when running ad campaigns.

9.1 Context

  • Average TTFB: 950ms, LCP: 3.1s.

  • CDN hit ratio only 35%; peak server CPU > 90%.

  • Revenue depended on Facebook Ads and Google Ads, with high costs but poor experience.

9.2 Implemented solution

  • Cloudflare CDN for assets + Cache Everything for HTML, with bypass for URLs with login/cart cookies.

  • Nginx microcache for HTML for 5s + stale-while-revalidate for 60s.

  • Redis Object Cache for WordPress, caching queries and fragments.

  • Asset versioning, WebP image compression, optimizing critical CSS.

9.3 Results

  • TTFB dropped to ~280ms (~70% reduction), LCP improved to 1.9s.

  • CDN hit ratio increased to 78%, origin offload ~65%.

  • Conversion rate increased by ~18% after 4 weeks; infrastructure costs decreased by ~30%.

“Improving 0.1–0.2s at critical touchpoints can create a meaningful revenue gap, especially for high-traffic campaigns.”

Takeaway: Multi-layer caching delivers clear impact on SEO and ROI.

10. A 7-step caching rollout plan for SMEs

Below is a practical roadmap suitable for small teams with mid-range budgets.

10.1 Preparation

  1. Classify content: dynamic/semi-static HTML, API, assets.

  2. Check current headers using DevTools/CLI.

  3. Choose the right CDN, reverse proxy, and Redis.

10.2 Execution

  1. Set up Cache-Control and ETag for assets and HTML.

  2. Enable CDN cache for assets and safe-to-cache HTML.

  3. Configure Nginx/Varnish microcaching for 1–10s.

  4. Install Redis Object Cache (WordPress) or integrate at the app layer.

  5. Version assets and preload key routes (homepage, category, PDP).

10.3 Operations

  1. Set up tag-based purge when content is updated.

  2. Monitor hit ratio, TTFB, and Core Web Vitals.

  3. Run traffic spike drills and prepare configuration rollback.

Takeaway: Move step by step, measure step by step, and continuously optimize.

Summary & Next Steps

Caching is the foundation for speeding up websites, reducing costs, and improving SEO. Start with standards-based HTTP caching, leverage a CDN, then add a reverse proxy and Redis to reach optimal speed. For SMEs, a step-by-step approach with consistent measurement can deliver clear results in 2–4 weeks.

If you’re building a new website, consider optimizing from the website design stage so caching is woven into the architecture. In the broader context of Digital Marketing, speed is a sustainable competitive advantage and a strong SEO enabler.

CTA: Need a caching blueprint for your website? Contact Hoàng Trung Digital for a free 30-minute audit and receive a speed optimization roadmap, Core Web Vitals plan, and a CDN/Redis/Nginx implementation plan that fits your budget.

Frequently Asked Questions

Share this article
Zalo

Found this article helpful?

Contact us for a free consultation about our services

Contact us

Bài viết liên quan