0Pricing
Edge Computing with Cloudflare Workers & Deno · บทเรียน

Workers Sites และ Pages

โฮสต์เว็บไซต์แบบสแตติกและแอปพลิเคชันหน้าเดียวโดยตรงบนระบบใกล้ผู้ใช้ของ Cloudflare ด้วย Workers Sites และ Pages

Workers Sites และ Pages เป็นบทเรียน Edge Computing with Cloudflare Workers & Deno ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Edge Computing with Cloudflare Workers & Deno และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Edge Computing with Cloudflare Workers & Deno มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Host Static Sites at the Edge

Welcome! In this lesson, we'll explore how to host your static websites and Single Page Applications (SPAs) directly on Cloudflare's global network edge.

This means your site's content is served from locations physically closer to your users, leading to incredibly fast load times and a smoother experience.

Introducing Workers Sites

Cloudflare Workers Sites is a feature that allows you to deploy static assets, like HTML, CSS, JavaScript, and images, directly to the Cloudflare edge using the Wrangler CLI.

  • It's perfect for simple static websites.
  • It works great for Single Page Applications (SPAs) built with frameworks like React, Vue, or Svelte.
  • You get the power of Workers to add dynamic logic if needed.

Benefits of Edge Hosting

Hosting your content at the edge offers several key advantages:

  • Blazing Fast Performance: Content is served from the nearest data center.
  • Global Reach: Your site is available worldwide with low latency.
  • Built-in Security: Leverages Cloudflare's network for DDoS protection and WAF.
  • Automatic SSL: Free, managed SSL certificates for secure connections.

Your First Workers Site HTML

Let's create a super simple index.html file. This will be the main page for our Workers Site.

Create a new folder (e.g., my-static-site) and put this file inside it:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Hello Edge!</title>
  <style>
    body { font-family: sans-serif; text-align: center; margin-top: 50px; }
  </style>
</head>
<body>
  <h1>Welcome to the Edge!</h1>
  <p>This site is hosted by Cloudflare Workers.</p>
</body>
</html>

Deploying a Workers Site

To deploy your static site, you'll use the Wrangler CLI. First, make sure you have Wrangler installed and configured.

Navigate to your project directory (e.g., my-static-site) and use the wrangler pages deploy command. This command helps deploy your static assets.

wrangler pages deploy ./ --project-name my-edge-app

# Or, if you have a build step:
# npm run build && wrangler pages deploy ./dist --project-name my-edge-app

Introducing Cloudflare Pages

While Workers Sites are great for quick deployments, Cloudflare Pages offers a more comprehensive platform for JAMstack and full-stack applications.

Pages integrates directly with your Git repository (GitHub, GitLab), providing automatic build and deploy pipelines.

Pages Features: CI/CD & Previews

Cloudflare Pages streamlines your development workflow:

  • Git Integration: Connects to your repo for automatic deployments on push.
  • Build Pipelines: Automatically builds your frontend framework (React, Vue, Next.js, etc.).
  • Preview Deployments: Every pull request gets a unique preview URL.
  • Custom Domains: Easily link your own domain.

Workers Sites vs. Pages: Key Differences

Both host static content at the edge, but serve different needs:

  • Workers Sites: Simpler, manual deployments via Wrangler CLI. Good for basic static sites or when you want more control over the Worker script logic.
  • Cloudflare Pages: Full-fledged CI/CD platform, Git-integrated, automatic builds, preview deployments. Ideal for modern JAMstack sites and SPAs.

SPAs and Client-Side Routing

Workers Sites and Pages are perfect for Single Page Applications (SPAs). SPAs often use client-side routing, meaning the server always serves the same index.html, and JavaScript handles navigation.

Cloudflare Pages handles this automatically. For Workers Sites, you might need a small Worker script to ensure all paths fall back to index.html.

Test Your Knowledge

You've learned about two powerful ways to host your web applications at the edge. Let's see if you can distinguish between them.

Recap: Edge Hosting for Web Apps

In this lesson, we explored how Cloudflare empowers you to host static sites and SPAs at the edge. We covered:

  • Workers Sites: For simple static deployments via Wrangler.
  • Cloudflare Pages: A full-featured platform with Git integration and CI/CD for JAMstack apps.
  • The incredible benefits of edge hosting, like speed and global reach.

Hosting at the edge brings your content closer to users, ensuring a fast, secure, and highly available web experience.

คำถามที่พบบ่อย

บทเรียน “Workers Sites และ Pages” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “Workers Sites และ Pages” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Edge Computing with Cloudflare Workers & Deno ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Edge Computing with Cloudflare Workers & Deno มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “Workers Sites และ Pages”

โฮสต์เว็บไซต์แบบสแตติกและแอปพลิเคชันหน้าเดียวโดยตรงบนระบบใกล้ผู้ใช้ของ Cloudflare ด้วย Workers Sites และ Pages คุณปฏิบัติ Edge Computing with Cloudflare Workers & Deno ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Edge Computing with Cloudflare Workers & Deno หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Edge Computing with Cloudflare Workers & Deno บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “Workers Sites และ Pages” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Edge Computing with Cloudflare Workers & Deno นี้ได้ไหม

ได้ บทเรียน Edge Computing with Cloudflare Workers & Deno ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. Workers Sites และ Pages
  2. การผสานเฟรมเวิร์กส่วนหน้า
  3. พร็อกซีฐานข้อมูลด้วย Deno
  4. การเรนเดอร์ฝั่งเซิร์ฟเวอร์ที่เอดจ์
← กลับไปที่ Edge Computing with Cloudflare Workers & Deno