Workers Workers Workers Cơ bản Entry កម្រិតចាប់ផ្តើម ~7 phút đọc · ~765 từ ~7 min read · ~686 words

Pages và Workers: khi nào dùng cái nào? Pages vs Workers: when to use which? Pages vs Workers: when to use which?

Pages thuận tiện deploy site tĩnh và frontend; Workers chạy code xử lý request tùy ý. Nhiều app hiện đại: Pages làm “mặt tiền”, Workers làm API và logic phía sau. Pages is great for static sites and frontends; Workers runs custom request-handling code. Many modern apps: Pages as the storefront, Workers as APIs and backend logic. Pages is great for static sites and frontends; Workers runs custom request-handling code. Many modern apps: Pages as the storefront, Workers as APIs and backend logic.

Hình 1: Cloudflare Developer Platform

Ứng dụng fullstack Fullstack applications Fullstack applications

Ví dụ fullstack trên Developer Platform — Workers/Pages, storage và AI services trong một kiến trúc thực tế. A practical example of how these services come together in a real fullstack application architecture. A practical example of how these services come together in a real fullstack application architecture.

Thuật ngữ: Concepts: Concepts: Workers · Pages · D1 · R2 · KV · Durable Objects

Sơ đồ chính thức ↗ Official diagram ↗ Official diagram ↗ · Serverless Serverless Serverless

Hai công cụ, một nền tảng — bắt đầu từ câu hỏi “bạn đang ship gì?” Two tools, one platform — start with “what are you shipping?” Two tools, one platform — start with “what are you shipping?”

Cloudflare Pages và Workers đều thuộc Developer Platform: bạn deploy lên mạng edge toàn cầu mà không tự quản lý máy chủ vật lý. Khác biệt nằm ở mô hình mental: Pages tối ưu cho file tĩnh và build frontend (HTML, CSS, JS, framework như Astro/React/Vue); Workers tối ưu cho đoạn code chạy mỗi khi có HTTP request — redirect, API, xác thực, ghép dữ liệu. Cloudflare Pages and Workers both live on the Developer Platform: you deploy to a global edge network without running physical servers. The mental model differs: Pages optimizes for static files and frontend builds (HTML, CSS, JS, frameworks like Astro/React/Vue); Workers optimizes for code that runs on each HTTP request — redirects, APIs, auth, data glue. Cloudflare Pages and Workers both live on the Developer Platform: you deploy to a global edge network without running physical servers. The mental model differs: Pages optimizes for static files and frontend builds (HTML, CSS, JS, frameworks like Astro/React/Vue); Workers optimizes for code that runs on each HTTP request — redirects, APIs, auth, data glue.

Câu hỏi đầu tiên: “Người dùng chủ yếu tải trang đã build sẵn, hay mỗi request cần logic riêng?” Nếu là portfolio, blog, landing marketing — Pages thường đủ và rất nhanh để bắt đầu. Nếu là API JSON, webhook, hoặc middleware phức tạp — Workers (hoặc Pages Functions) phù hợp hơn. First question: “Do users mostly load prebuilt pages, or does each request need custom logic?” For a portfolio, blog, or marketing landing — Pages is often enough and very fast to start. For JSON APIs, webhooks, or complex middleware — Workers (or Pages Functions) fits better. First question: “Do users mostly load prebuilt pages, or does each request need custom logic?” For a portfolio, blog, or marketing landing — Pages is often enough and very fast to start. For JSON APIs, webhooks, or complex middleware — Workers (or Pages Functions) fits better.

Blog.cloudflare.com thường mô tả Pages và Workers như hai cánh của cùng một nhà: nhiều tutorial full-stack kết hợp Pages deploy frontend + Worker xử lý form/API. Bạn không bắt buộc chọn một và loại bỏ hẳn cái kia. The Cloudflare Blog often describes Pages and Workers as two wings of the same house: many full-stack tutorials combine Pages for the frontend plus a Worker for forms/APIs. You are not forced to pick one and banish the other. The Cloudflare Blog often describes Pages and Workers as two wings of the same house: many full-stack tutorials combine Pages for the frontend plus a Worker for forms/APIs. You are not forced to pick one and banish the other.

Hình 1: Cloudflare Developer Platform

Ứng dụng fullstack Fullstack applications Fullstack applications

Ví dụ fullstack trên Developer Platform — Workers/Pages, storage và AI services trong một kiến trúc thực tế. A practical example of how these services come together in a real fullstack application architecture. A practical example of how these services come together in a real fullstack application architecture.

Thuật ngữ: Concepts: Concepts: Workers · Pages · D1 · R2 · KV · Durable Objects

Sơ đồ chính thức ↗ Official diagram ↗ Official diagram ↗ · Serverless Serverless Serverless

Cloudflare Pages phù hợp khi nào? When is Cloudflare Pages the right fit? When is Cloudflare Pages the right fit?

Pages shine với site tĩnh hoặc JAMstack: build trên CI (Git push), Cloudflare phục vụ file từ edge, HTTPS và preview branch có sẵn. Hub này chính là ví dụ Astro build ra static + Functions — pattern quen thuộc với Pages. Pages shines for static or JAMstack sites: build in CI (git push), Cloudflare serves files from the edge with HTTPS and preview branches built in. This hub itself is an Astro static build plus Functions — a familiar Pages pattern. Pages shines for static or JAMstack sites: build in CI (git push), Cloudflare serves files from the edge with HTTPS and preview branches built in. This hub itself is an Astro static build plus Functions — a familiar Pages pattern.

Bạn có ít hoặc không có server “luôn bật”. Mỗi deploy là một phiên bản file. Thay đổi nội dung = build lại và publish — không SSH vào máy. Phù hợp team nhỏ, tài liệu, marketing, và prototype UI nhanh. You have little or no always-on server. Each deploy is a version of files. Content changes mean rebuild and publish — no SSH into a box. Great for small teams, docs, marketing, and fast UI prototypes. You have little or no always-on server. Each deploy is a version of files. Content changes mean rebuild and publish — no SSH into a box. Great for small teams, docs, marketing, and fast UI prototypes.

Pages cũng hỗ trợ Functions (serverless handlers gắn với project Pages) cho API nhẹ — nhưng khi logic phình to, nhiều route, hoặc cần bindings phức tạp, team thường tách Worker riêng hoặc dùng Workers làm backend chính. Pages also supports Functions (serverless handlers attached to a Pages project) for light APIs — but when logic grows, routes multiply, or bindings get complex, teams often split a dedicated Worker or use Workers as the main backend. Pages also supports Functions (serverless handlers attached to a Pages project) for light APIs — but when logic grows, routes multiply, or bindings get complex, teams often split a dedicated Worker or use Workers as the main backend.

Cloudflare Workers phù hợp khi nào? When is Cloudflare Workers the right fit? When is Cloudflare Workers the right fit?

Workers là “hàm của bạn chạy tại edge” cho mọi request khớp route. Use case điển hình: API REST nhỏ, xác thực token, rewrite URL, A/B test header, proxy an toàn tới dịch vụ nội bộ, xử lý webhook từ Stripe/GitHub. Workers are “your function runs at the edge” for every matching request. Typical uses: small REST APIs, token auth, URL rewrites, header-based A/B tests, safe proxies to internal services, webhooks from Stripe/GitHub. Workers are “your function runs at the edge” for every matching request. Typical uses: small REST APIs, token auth, URL rewrites, header-based A/B tests, safe proxies to internal services, webhooks from Stripe/GitHub.

Workers nối với R2, D1, KV, Durable Objects, Workers AI qua bindings — không cần hard-code secret trong trình duyệt. Đây là lý do nhiều ứng dụng “không server” thật sự đặt logic nhạy cảm trên Worker, còn Pages chỉ phục vụ UI. Workers connect to R2, D1, KV, Durable Objects, and Workers AI via bindings — without hard-coding secrets in the browser. That is why many “serverless” apps put sensitive logic on a Worker while Pages serves only the UI. Workers connect to R2, D1, KV, Durable Objects, and Workers AI via bindings — without hard-coding secrets in the browser. That is why many “serverless” apps put sensitive logic on a Worker while Pages serves only the UI.

Nếu bạn đã đọc bài Workers giới thiệu trên hub, hãy coi Workers là động cơ; Pages là showroom. Động cơ có thể chạy một mình (API-only), showroom có thể đứng một mình (site tĩnh thuần) — kết hợp khi cần cả hai. If you read the Workers intro on this hub, treat Workers as the engine and Pages as the showroom. The engine can run alone (API-only); the showroom can stand alone (pure static) — combine when you need both. If you read the Workers intro on this hub, treat Workers as the engine and Pages as the showroom. The engine can run alone (API-only); the showroom can stand alone (pure static) — combine when you need both.

Chi phí và giới hạn: cả hai đều có free tier hào phóng cho học tập; production cần đọc pricing và giới hạn CPU/time per request của Workers. Đừng chạy job nặng giờ trên Worker — dùng queue hoặc dịch vụ phù hợp. Cost and limits: both have generous free tiers for learning; production needs pricing docs and Workers CPU/time limits. Do not run hour-long jobs on a Worker — use queues or a fitting service instead. Cost and limits: both have generous free tiers for learning; production needs pricing docs and Workers CPU/time limits. Do not run hour-long jobs on a Worker — use queues or a fitting service instead.

Mô hình kết hợp thực tế — và lộ trình học tiếp Real-world combos — and what to learn next Real-world combos — and what to learn next

Mô hình 1 — Pages + Worker API: UI trên Pages, fetch tới worker.example.com/api. Mô hình 2 — Monorepo: frontend Pages, folder worker riêng deploy song song. Mô hình 3 — Chỉ Workers phục vụ HTML từ R2 hoặc template — ít phổ biến với người mới nhưng hợp lệ. Pattern 1 — Pages + Worker API: UI on Pages, fetch worker.example.com/api. Pattern 2 — Monorepo: frontend on Pages, separate worker folder deployed alongside. Pattern 3 — Workers-only serving HTML from R2 or templates — less common for beginners but valid. Pattern 1 — Pages + Worker API: UI on Pages, fetch worker.example.com/api. Pattern 2 — Monorepo: frontend on Pages, separate worker folder deployed alongside. Pattern 3 — Workers-only serving HTML from R2 or templates — less common for beginners but valid.

Chọn Pages khi 80% công việc là nội dung và UI đã build. Chọn Workers khi 80% là logic request, tích hợp bên thứ ba, hoặc dữ liệu động. Phân vân? Bắt đầu Pages cho landing, thêm Worker khi form hoặc API xuất hiện — đúng với cách nhiều startup tiến hóa. Choose Pages when 80% of the work is content and built UI. Choose Workers when 80% is request logic, third-party integration, or dynamic data. Unsure? Start with Pages for the landing page, add a Worker when forms or APIs appear — how many startups evolve. Choose Pages when 80% of the work is content and built UI. Choose Workers when 80% is request logic, third-party integration, or dynamic data. Unsure? Start with Pages for the landing page, add a Worker when forms or APIs appear — how many startups evolve.

Tiếp theo trên hub: đọc Developer Platform overview, thử deploy static site use case, rồi bài Workers AI nếu bạn muốn thêm chatbot. Mỗi bước nhỏ, một repo demo — học edge tốt nhất bằng deploy thật. Next on this hub: read the Developer Platform overview, try the deploy-static-site use case, then the Workers AI post if you want a chatbot. Small steps, one demo repo — you learn the edge best by deploying for real. Next on this hub: read the Developer Platform overview, try the deploy-static-site use case, then the Workers AI post if you want a chatbot. Small steps, one demo repo — you learn the edge best by deploying for real.

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: Kiến trúc truyền thống một vùng

API serverless toàn cầu Serverless global APIs Serverless global APIs

Ví dụ kiến trúc API serverless trên Cloudflare — compute và data product (Workers, D1, R2) tương tác thế nào. An example architecture of a serverless API on Cloudflare and aims to illustrate how different compute and data products could interact with each other. An example architecture of a serverless API on Cloudflare and aims to illustrate how different compute and data products could interact with each other.

Thuật ngữ: Concepts: Concepts: Workers · D1 · R2 · Global API · Edge compute

Sơ đồ chính thức ↗ Official diagram ↗ Official diagram ↗ · Serverless Serverless Serverless

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

Pages Functions có thay hẳn Workers không? Do Pages Functions fully replace Workers? Do Pages Functions fully replace Workers?

Không hẳn. Functions tiện cho API nhỏ gắn với project Pages. Workers độc lập linh hoạt hơn cho routing phức tạp, nhiều service, hoặc microservice riêng. Nhiều team dùng cả hai. Not entirely. Functions are handy for small APIs tied to a Pages project. Standalone Workers are more flexible for complex routing, many services, or separate microservices. Many teams use both. Not entirely. Functions are handy for small APIs tied to a Pages project. Standalone Workers are more flexible for complex routing, many services, or separate microservices. Many teams use both.

Tôi chỉ có landing HTML — có cần Workers không? I only have an HTML landing — do I need Workers? I only have an HTML landing — do I need Workers?

Thường không. Pages (hoặc static hosting qua Pages) đủ. Chỉ thêm Worker khi bạn cần form backend, auth, hoặc API động. Usually no. Pages (or static hosting via Pages) is enough. Add a Worker only when you need a form backend, auth, or dynamic APIs. Usually no. Pages (or static hosting via Pages) is enough. Add a Worker only when you need a form backend, auth, or dynamic APIs.

Deploy Pages và Workers có chung domain không? Can Pages and Workers share one domain? Can Pages and Workers share one domain?

Có. Ví dụ www trỏ Pages, api subdomain trỏ Worker. Hoặc Worker làm reverse proxy trước origin/Pages. Cấu hình DNS và route trong dashboard hoặc wrangler. Yes. Example: www points to Pages, api subdomain to a Worker. Or a Worker reverse-proxies before origin/Pages. Configure DNS and routes in the dashboard or wrangler. Yes. Example: www points to Pages, api subdomain to a Worker. Or a Worker reverse-proxies before origin/Pages. Configure DNS and routes in the dashboard or wrangler.

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 are Cloudflare Workers? Serverless at the edge, explained simply
Workers Workers Workers Cơ bản Entry កម្រិតចាប់ផ្តើម ~7 phút ~7 min ~7 នាទី

Cloudflare Workers là gì? Serverless ở “mép mạng” giải thích đơn giản What are Cloudflare Workers? Serverless at the edge, explained simply What are Cloudflare Workers? Serverless at the edge, explained simply

Workers giống thuê “người trực” ngay gần khách hàng: nhận request, xử lý nhanh, trả kết quả — bạn không phải tự mua và bảo trì cả tòa nhà server. Workers are like stationing helpers near customers: take a request, handle it quickly, return a result — without buying and maintaining a whole server building. Workers are like stationing helpers near customers: take a request, handle it quickly, return a result — without buying and maintaining a whole server building.

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

Cloudflare Developer Platform: build global apps without managing servers yourself
Developer Platform Developer Platform Developer Platform Trung cấp Intermediate កម្រិតមធ្យម ~9 phút ~9 min ~9 នាទី

Cloudflare Developer Platform: xây ứng dụng toàn cầu mà không tự quản lý server Cloudflare Developer Platform: build global apps without managing servers yourself Cloudflare Developer Platform: build global apps without managing servers yourself

Developer Platform giống bộ lego edge: compute (Workers), hộp đựng (R2/KV/D1), AI, và lớp bảo vệ — lắp theo use case thay vì mua cả trung tâm dữ liệu. The Developer Platform is like an edge Lego set: compute (Workers), storage boxes (R2/KV/D1), AI, and protection layers — assemble by use case instead of buying a whole data center. The Developer Platform is like an edge Lego set: compute (Workers), storage boxes (R2/KV/D1), AI, and protection layers — assemble by use case instead of buying a whole data center.

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

What is R2? Object storage on Cloudflare without egress sticker shock
Developer Platform Developer Platform Developer Platform Cơ bản Entry កម្រិតចាប់ផ្តើម ~7 phút ~7 min ~7 នាទី

R2 là gì? Lưu file trên Cloudflare mà không “sợ” phí egress What is R2? Object storage on Cloudflare without egress sticker shock What is R2? Object storage on Cloudflare without egress sticker shock

R2 là kho object trên Cloudflare — giống S3 nhưng không tính phí egress khi phục vụ qua mạng Cloudflare. Hợp ảnh user, backup, và file tĩnh cho Workers/Pages. R2 is Cloudflare object storage — S3-like but without egress fees when served through Cloudflare’s network. Great for user images, backups, and static files for Workers/Pages. R2 is Cloudflare object storage — S3-like but without egress fees when served through Cloudflare’s network. Great for user images, backups, and static files for Workers/Pages.

Đọ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.