CDN CDN CDN Trung cấp Intermediate កម្រិតមធ្យម ~8 phút đọc · ~774 từ ~8 min read · ~644 words

Cache Rules: kiểm soát cache không phá giỏ hàng Cache Rules: control caching without breaking carts Cache Rules: control caching without breaking carts

Cache Rules cho phép “cache ảnh/CSS, không cache /cart” — rõ ràng hơn bật cache toàn site. Hiểu thứ tự rule và purge để deploy không khiến khách thấy bản cũ. Cache Rules let you “cache images/CSS, not /cart” — clearer than caching the whole site. Learn rule order and purge so deploys do not show stale pages. Cache Rules let you “cache images/CSS, not /cart” — clearer than caching the whole site. Learn rule order and purge so deploys do not show stale pages.

Hình 1: Tổng quan luồng dữ liệu

Thiết kế kiến trúc hiệu năng web phân tán Designing a distributed web performance architecture Designing a distributed web performance architecture

Pattern L7: data flow, cache tiers, deployment models — giảm latency và cải thiện Core Web Vitals. A prescriptive pattern for building a Cloudflare-based L7 performance architecture that reduces latency, raises cache efficiency, and improves Core Web Vitals. A prescriptive pattern for building a Cloudflare-based L7 performance architecture that reduces latency, raises cache efficiency, and improves Core Web Vitals.

Thuật ngữ: Concepts: Concepts: CDN · Cache · Core Web Vitals · Smart Shield · Argo

Sơ đồ chính thức ↗ Official diagram ↗ Official diagram ↗ · Phân phối nội dung Content Delivery Content Delivery

Vì sao “cache mặc định” không đủ cho site thật? Why “default cache” is not enough for real sites Why “default cache” is not enough for real sites

CDN cache giúp site nhanh — nhưng site thương mại, SaaS, hoặc có đăng nhập cần quy tắc tinh: ảnh sản phẩm cache lâu; trang /account, /checkout, /api/me không cache; HTML marketing có thể cache ngắn. Không phân biệt → khách A thấy giỏ của khách B, hoặc form login lỗi — lỗi nguy hiểm hơn chậm vài trăm ms. CDN cache speeds sites up — but shops, SaaS, and logged-in experiences need fine rules: product images cache long; /account, /checkout, /api/me do not; marketing HTML might cache briefly. Without separation → user A sees user B’s cart or broken login — worse than a few hundred ms delay. CDN cache speeds sites up — but shops, SaaS, and logged-in experiences need fine rules: product images cache long; /account, /checkout, /api/me do not; marketing HTML might cache briefly. Without separation → user A sees user B’s cart or broken login — worse than a few hundred ms delay.

Cloudflare Cache Rules (và các rule engine mới) thay dần Page Rules cũ cho nhiều use case cache: biểu thức theo hostname, path, header, cookie; hành động bypass, edge TTL, cache key tùy chỉnh. Blog.cloudflare.com về cache thường khuyên dùng Cache Rules cho cấu hình mới. Cloudflare Cache Rules (and newer rule engines) gradually replace legacy Page Rules for many cache cases: expressions by hostname, path, header, cookie; actions like bypass, edge TTL, custom cache keys. Cloudflare Blog cache posts often recommend Cache Rules for new config. Cloudflare Cache Rules (and newer rule engines) gradually replace legacy Page Rules for many cache cases: expressions by hostname, path, header, cookie; actions like bypass, edge TTL, custom cache keys. Cloudflare Blog cache posts often recommend Cache Rules for new config.

Bài này giả định bạn đã đọc giới thiệu CDN trên hub và site đang proxied (đám mây cam). Nếu chưa, quay lại bài DNS/proxy và CDN cơ bản trước — rule không có tác dụng đúng trên DNS only. This post assumes you read the hub CDN intro and your site is proxied (orange cloud). If not, revisit DNS/proxy and CDN basics first — rules do not apply correctly on DNS-only. This post assumes you read the hub CDN intro and your site is proxied (orange cloud). If not, revisit DNS/proxy and CDN basics first — rules do not apply correctly on DNS-only.

Hình 1: Tổng quan luồng dữ liệu

Thiết kế kiến trúc hiệu năng web phân tán Designing a distributed web performance architecture Designing a distributed web performance architecture

Pattern L7: data flow, cache tiers, deployment models — giảm latency và cải thiện Core Web Vitals. A prescriptive pattern for building a Cloudflare-based L7 performance architecture that reduces latency, raises cache efficiency, and improves Core Web Vitals. A prescriptive pattern for building a Cloudflare-based L7 performance architecture that reduces latency, raises cache efficiency, and improves Core Web Vitals.

Thuật ngữ: Concepts: Concepts: CDN · Cache · Core Web Vitals · Smart Shield · Argo

Sơ đồ chính thức ↗ Official diagram ↗ Official diagram ↗ · Phân phối nội dung Content Delivery Content Delivery

Cache Rules hoạt động thế nào — thứ tự và match How Cache Rules work — order and matching How Cache Rules work — order and matching

Mỗi rule có điều kiện (when) và hành động (then): ví dụ “URI Path contains /static/” → Cache eligibility: eligible, Edge TTL 1 tháng. Rule khác: “URI Path starts with /cart” → Bypass cache. Cloudflare đánh giá theo thứ tự ưu tiên bạn sắp — rule cụ thể hơn nên đứng trước rule chung. Each rule has a condition (when) and action (then): e.g. “URI Path contains /static/” → Cache eligibility: eligible, Edge TTL 1 month. Another rule: “URI Path starts with /cart” → Bypass cache. Cloudflare evaluates in your priority order — more specific rules should sit above broad ones. Each rule has a condition (when) and action (then): e.g. “URI Path contains /static/” → Cache eligibility: eligible, Edge TTL 1 month. Another rule: “URI Path starts with /cart” → Bypass cache. Cloudflare evaluates in your priority order — more specific rules should sit above broad ones.

Bạn có thể match cookie session (wordpress_logged_in, sessionid) để bypass cache cho user đã login — hữu ích khi HTML trang chủ giống nhau nhưng header khác. Cẩn thận: match cookie sai có thể bypass quá nhiều và mất lợi ích CDN. You can match session cookies (wordpress_logged_in, sessionid) to bypass cache for logged-in users — useful when homepage HTML looks the same but headers differ. Careful: wrong cookie matches bypass too much and waste CDN benefits. You can match session cookies (wordpress_logged_in, sessionid) to bypass cache for logged-in users — useful when homepage HTML looks the same but headers differ. Careful: wrong cookie matches bypass too much and waste CDN benefits.

Cache Rules khác Page Rules ở chỗ tập trung vào cache/CDN, tích hợp dashboard Rules mới, và biểu thức linh hoạt hơn. Page Rules cũ có thể vẫn tồn tại trên zone legacy — tránh trùng mâu thuẫn (một chỗ cache, một chỗ bypass). Khi migrate, ghi lại hành vi cũ rồi test từng luồng. Cache Rules differ from Page Rules by focusing on cache/CDN, fitting the new Rules dashboard, and richer expressions. Legacy zones may still have Page Rules — avoid conflicting overlap (one caches, one bypasses). When migrating, document old behavior then test each flow. Cache Rules differ from Page Rules by focusing on cache/CDN, fitting the new Rules dashboard, and richer expressions. Legacy zones may still have Page Rules — avoid conflicting overlap (one caches, one bypasses). When migrating, document old behavior then test each flow.

Developer tip: sau khi thêm rule, dùng curl -I hoặc DevTools Network xem header CF-Cache-Status (HIT, MISS, BYPASS, DYNAMIC) — học nhanh hơn đoán trong dashboard. Developer tip: after adding rules, use curl -I or DevTools Network for CF-Cache-Status (HIT, MISS, BYPASS, DYNAMIC) — faster than guessing in the dashboard. Developer tip: after adding rules, use curl -I or DevTools Network for CF-Cache-Status (HIT, MISS, BYPASS, DYNAMIC) — faster than guessing in the dashboard.

Mẫu rule an toàn: static, HTML, login, API Safe rule patterns: static, HTML, login, API Safe rule patterns: static, HTML, login, API

Static assets (/assets/*, *.css, *.js, *.woff2, ảnh sản phẩm): cache edge dài, respect origin nếu origin gửi Cache-Control hợp lý. Marketing pages (/blog/*, landing): cache ngắn hoặc stale-while-revalidate nếu nội dung đổi thường xuyên. Static assets (/assets/*, *.css, *.js, *.woff2, product images): long edge cache, respect origin when origin sends sensible Cache-Control. Marketing pages (/blog/*, landing): short cache or stale-while-revalidate if content changes often. Static assets (/assets/*, *.css, *.js, *.woff2, product images): long edge cache, respect origin when origin sends sensible Cache-Control. Marketing pages (/blog/*, landing): short cache or stale-while-revalidate if content changes often.

Bypass bắt buộc: /cart, /checkout, /account, /admin, /api/* trả dữ liệu user-specific, webhook endpoints. WordPress: bypass wp-admin và thường cả trang có comment form động. Shopify/Woo: theo doc nền tảng — đừng copy rule blog WordPress mù quáng. Mandatory bypass: /cart, /checkout, /account, /admin, /api/* returning user-specific data, webhook endpoints. WordPress: bypass wp-admin and often comment-heavy pages. Shopify/Woo: follow platform docs — do not blindly copy WordPress blog rules. Mandatory bypass: /cart, /checkout, /account, /admin, /api/* returning user-specific data, webhook endpoints. WordPress: bypass wp-admin and often comment-heavy pages. Shopify/Woo: follow platform docs — do not blindly copy WordPress blog rules.

API JSON public (read-only) đôi khi cache được với TTL ngắn và cache key có query — chỉ khi bạn chắc không lộ dữ liệu riêng. Nghi ngờ → bypass. WAF và cache là hai lớp: rule cache không thay thế kiểm tra authorization trên origin. Public read-only JSON APIs can sometimes cache with short TTL and query-aware cache keys — only when sure no private data leaks. When unsure → bypass. WAF and cache are separate layers: cache rules do not replace origin authorization checks. Public read-only JSON APIs can sometimes cache with short TTL and query-aware cache keys — only when sure no private data leaks. When unsure → bypass. WAF and cache are separate layers: cache rules do not replace origin authorization checks.

Purge khi deploy — và checklist sau khi đổi rule Purge on deploy — and checklist after rule changes Purge on deploy — and checklist after rule changes

Deploy frontend mới mà quên purge: user vẫn thấy JS/CSS cũ từ edge — bug “ghost” khó debug. Thói quen: purge by tag hoặc prefix /assets/* sau mỗi release quan trọng; hoặc dùng version query (?v=20260827). CI có thể gọi API purge tự động. Deploy new frontend without purge: users keep old JS/CSS from edge — ghost bugs are hard to debug. Habit: purge by tag or /assets/* prefix after major releases; or versioned query strings (?v=20260827). CI can call the purge API automatically. Deploy new frontend without purge: users keep old JS/CSS from edge — ghost bugs are hard to debug. Habit: purge by tag or /assets/* prefix after major releases; or versioned query strings (?v=20260827). CI can call the purge API automatically.

Sau khi sửa Cache Rules: test đăng nhập, thêm giỏ hàng, thanh toán sandbox; mở tab ẩn danh và tab đã login song song; kiểm tra API mobile app nếu có. Ghi lại rule đã thêm — team sau sẽ cảm ơn. After editing Cache Rules: test login, add-to-cart, sandbox checkout; open incognito and logged-in tabs side by side; check mobile app APIs if any. Document rules you added — future you will thank you. After editing Cache Rules: test login, add-to-cart, sandbox checkout; open incognito and logged-in tabs side by side; check mobile app APIs if any. Document rules you added — future you will thank you.

Đọc thêm trang Content Delivery (mục Cache Rules) trên hub, bài CDN cơ bản, và WAF nếu bạn vừa siết cache vừa mở rộng surface API. Cache đúng là nghệ thuật cân bằng tốc độ và đúng dữ liệu — không phải nút “max speed” một lần. Read the hub Content Delivery section (Cache Rules), the CDN basics post, and WAF if you tighten cache while expanding API surface. Good caching balances speed and correct data — not a one-time “max speed” button. Read the hub Content Delivery section (Cache Rules), the CDN basics post, and WAF if you tighten cache while expanding API surface. Good caching balances speed and correct data — not a one-time “max speed” button.

Hình minh họa Cloudflare Cloudflare visuals Cloudflare visuals

Sơ đồ Reference Architecture chính thức và (khi có) ảnh Dashboard — giúp đối chiếu khi học. Official Reference Architecture diagrams and (when available) Dashboard screenshots — useful while you learn. Official Reference Architecture diagrams and (when available) Dashboard screenshots — useful while you learn.

Hình 1: Cloudflare Image Resizing and R2

Tối ưu phân phối ảnh với Image Resizing và R2 Optimizing image delivery with Cloudflare image resizing and R2 Optimizing image delivery with Cloudflare image resizing and R2

Giải pháp tối ưu phân phối ảnh, mở rộng được và hiệu năng cao — Image Resizing kết hợp R2. Learn how to get a scalable, high-performance solution to optimizing image delivery. Learn how to get a scalable, high-performance solution to optimizing image delivery.

Thuật ngữ: Concepts: Concepts: Image Resizing · R2 · Transformations · Cache

Sơ đồ chính thức ↗ Official diagram ↗ Official diagram ↗ · Phân phối nội dung Content Delivery Content Delivery

Câu hỏi thường gặp Frequently asked questions Frequently asked questions

Cache Rules có xóa Page Rules cũ ngay không? Should you delete old Page Rules immediately? Should you delete old Page Rules immediately?

Không vội. Tạo Cache Rules tương đương, test kỹ, rồi tắt Page Rules trùng chức năng từng cái. Giữ ghi chú để rollback nếu checkout lỗi sau deploy. Not in a rush. Build equivalent Cache Rules, test thoroughly, then disable overlapping Page Rules one by one. Keep notes to rollback if checkout breaks after deploy. Not in a rush. Build equivalent Cache Rules, test thoroughly, then disable overlapping Page Rules one by one. Keep notes to rollback if checkout breaks after deploy.

Purge Everything có nguy hiểm không? Is Purge Everything dangerous? Is Purge Everything dangerous?

Không xóa origin — chỉ xóa bản copy edge. Site có thể chậm tạm thời (MISS) khi cache làm lại. Dùng khi cần; hàng ngày prefer purge theo URL/tag để ít ảnh hưởng traffic. It does not delete origin — only edge copies. The site may be briefly slower (MISS) while cache rebuilds. Use when needed; day-to-day prefer URL/tag purge for less traffic impact. It does not delete origin — only edge copies. The site may be briefly slower (MISS) while cache rebuilds. Use when needed; day-to-day prefer URL/tag purge for less traffic impact.

HTML động có cache được không? Can dynamic HTML be cached? Can dynamic HTML be cached?

Có thể với edge side includes hoặc cache theo segment — nâng cao. Người mới nên bypass HTML cá nhân hóa; chỉ cache phần static rõ ràng. Sai ở đây gây lộ dữ liệu nhanh hơn mọi lỗi performance khác. Possible with edge includes or segmented cache — advanced. Beginners should bypass personalized HTML; cache only clearly static parts. Mistakes here leak data faster than any performance bug. Possible with edge includes or segmented cache — advanced. Beginners should bypass personalized HTML; cache only clearly static parts. Mistakes here leak data faster than any performance bug.

Học tiếp trên hub (on-page backlinks) Keep learning on this hub (on-page links) Keep learning on this hub (on-page links)

Nguồn tham khảo (blog.cloudflare.com) Sources (blog.cloudflare.com) Sources (blog.cloudflare.com)

Nội dung được viết lại để dễ hiểu hơn; luôn đọc bài gốc trên blog.cloudflare.com và docs chính thức khi cần chi tiết kỹ thuật hoặc cập nhật mới nhất. Content is rewritten for clarity; always read the original posts on blog.cloudflare.com and official docs for technical detail or the latest updates. Content is rewritten for clarity; always read the original posts on blog.cloudflare.com and official docs for technical detail or the latest updates.

What is a CDN? Understanding Cloudflare Cache in plain language
CDN CDN CDN Cơ bản Entry កម្រិតចាប់ផ្តើម ~6 phút ~6 min ~6 នាទី

CDN là gì? Hiểu Cloudflare Cache như đang giải thích cho bạn bè What is a CDN? Understanding Cloudflare Cache in plain language What is a CDN? Understanding Cloudflare Cache in plain language

CDN giống mạng kho hàng gần người dùng. Cloudflare Cache giữ bản sao nội dung tĩnh gần bạn — trang mở nhanh hơn, server gốc đỡ “mệt”. Think of a CDN as warehouses near your users. Cloudflare Cache keeps copies of static content close by — pages load faster and origin servers work less. Think of a CDN as warehouses near your users. Cloudflare Cache keeps copies of static content close by — pages load faster and origin servers work less.

Đọc bài → Read post → អានអត្ថបទ →

DNS and the orange cloud: Cloudflare proxy explained simply
CDN CDN CDN Cơ bản Entry កម្រិតចាប់ផ្តើម ~7 phút ~7 min ~7 នាទី

DNS và đám mây cam: proxy Cloudflare giải thích đơn giản DNS and the orange cloud: Cloudflare proxy explained simply DNS and the orange cloud: Cloudflare proxy explained simply

Đám mây cam nghĩa là traffic website đi qua mạng Cloudflare trước khi tới server gốc — bạn nhận CDN, bảo vệ và nhiều tính năng hơn so với chỉ trỏ DNS. The orange cloud means site traffic passes through Cloudflare’s network before your origin — you get CDN, protection, and more than DNS-only pointing. The orange cloud means site traffic passes through Cloudflare’s network before your origin — you get CDN, protection, and more than DNS-only pointing.

Đọc bài → Read post → អានអត្ថបទ →

What is a WAF? Cloudflare website protection explained for non-specialists
Bảo mật Security សុវត្ថិភាព Cơ bản Entry កម្រិតចាប់ផ្តើម ~7 phút ~7 min ~7 នាទី

WAF là gì? Bảo vệ website Cloudflare theo cách người không chuyên IT cũng hiểu What is a WAF? Cloudflare website protection explained for non-specialists What is a WAF? Cloudflare website protection explained for non-specialists

WAF giống bảo vệ cửa ra vào của website: xem ai đang gõ cửa, chặn hành vi đáng ngờ, rồi mới cho vào bên trong (origin). A WAF is like a doorman for your website: it checks who is knocking, blocks suspicious behavior, then lets safe traffic through to your origin. A WAF is like a doorman for your website: it checks who is knocking, blocks suspicious behavior, then lets safe traffic through to your origin.

Đọc bài → Read post → អានអត្ថបទ →

Xem tất cả bài blog Browse all blog posts Browse all blog posts

Chuỗi bài AI · Security · CDN · Workers · Developer Platform — viết lại cho người mới và trung cấp. AI · Security · CDN · Workers · Developer Platform — rewritten for entry and intermediate learners. AI · Security · CDN · Workers · Developer Platform — rewritten for entry and intermediate learners.