Workers Workers Workers Cơ bản Entry កម្រិតចាប់ផ្តើម ~7 phút đọc · ~784 từ ~7 min read · ~699 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?

Workers Static Assets được Cloudflare khuyến nghị cho dự án mới, kể cả site tĩnh; Pages vẫn được hỗ trợ. Một ứng dụng có thể dùng Workers cho cả frontend và API, hoặc kết hợp Pages với Worker API. Cloudflare recommends Workers Static Assets for new projects, including static sites; Pages remains supported. Apps can serve both frontend and APIs from Workers, or combine Pages with a Worker API. Cloudflare recommends Workers Static Assets for new projects, including static sites; Pages remains supported. Apps can serve both frontend and APIs from Workers, or combine Pages with a Worker API.

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.

Với dự án mới, Cloudflare khuyến nghị Workers Static Assets cho site tĩnh, SPA và ứng dụng full-stack: không cần Worker script nếu chỉ phục vụ file tĩnh. Pages vẫn được hỗ trợ và phù hợp với các dự án Pages hiện có; API, webhook hay middleware có thể đặt trên Workers hoặc Pages Functions. For new projects, Cloudflare recommends Workers Static Assets for static sites, SPAs, and full-stack apps: a purely static site needs no Worker script. Pages remains supported and can still suit existing Pages projects; APIs, webhooks, and middleware can use Workers or Pages Functions. For new projects, Cloudflare recommends Workers Static Assets for static sites, SPAs, and full-stack apps: a purely static site needs no Worker script. Pages remains supported and can still suit existing Pages projects; APIs, webhooks, and middleware can use Workers or Pages Functions.

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 — Workers Static Assets cho frontend, kèm Worker xử lý API và bindings trong một ứng dụng. Mô hình 2 — Pages hiện có + Worker API riêng. Mô hình 3 — Monorepo deploy nhiều dịch vụ độc lập nếu thực sự cần tách vòng đời. Pattern 1 — Workers Static Assets for the frontend, with a Worker for APIs and bindings in one app. Pattern 2 — an existing Pages frontend plus a separate Worker API. Pattern 3 — a monorepo with independent services when separate release lifecycles are needed. Pattern 1 — Workers Static Assets for the frontend, with a Worker for APIs and bindings in one app. Pattern 2 — an existing Pages frontend plus a separate Worker API. Pattern 3 — a monorepo with independent services when separate release lifecycles are needed.

Với dự án mới, Cloudflare khuyến nghị Workers Static Assets — kể cả landing tĩnh; không cần Worker script nếu chỉ phục vụ file. Pages vẫn được hỗ trợ cho các dự án Pages hiện có. Có thể thêm API và bindings trong cùng một ứng dụng Workers khi cần. For new projects, Cloudflare recommends Workers Static Assets — including static landing pages; a purely static site needs no Worker script. Pages remains supported for existing Pages projects. You can add APIs and bindings in the same Workers app when needed. For new projects, Cloudflare recommends Workers Static Assets — including static landing pages; a purely static site needs no Worker script. Pages remains supported for existing Pages projects. You can add APIs and bindings in the same Workers app when needed.

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?

Với dự án mới, dùng Workers Static Assets: site tĩnh thuần không cần Worker script. Pages vẫn được hỗ trợ nếu bạn đã có dự án Pages. Chỉ cần thêm logic Worker khi có form, xác thực hoặc API động. For a new project, use Workers Static Assets: a purely static site needs no Worker script. Pages remains supported if you already have a Pages project. Add Worker logic only when you need a form backend, auth, or dynamic APIs. For a new project, use Workers Static Assets: a purely static site needs no Worker script. Pages remains supported if you already have a Pages project. Add Worker logic 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, API kiểu S3. Mọi đường truy cập đều không tính egress: Workers, S3 API, r2.dev và custom domain. Chi phí là storage, thao tác Class A/B, và phí lấy dữ liệu nếu dùng Infrequent Access. R2 is Cloudflare object storage with an S3-style API. Egress is free on every access path: Workers, the S3 API, r2.dev, and custom domains. You pay for storage, Class A/B operations, and data retrieval if you use Infrequent Access. R2 is Cloudflare object storage with an S3-style API. Egress is free on every access path: Workers, the S3 API, r2.dev, and custom domains. You pay for storage, Class A/B operations, and data retrieval if you use Infrequent Access.

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