Workers Sites i Pages
Hostuj witryny statyczne i aplikacje jednostronicowe bezpośrednio na brzegu sieci Cloudflare za pomocą Workers Sites i Pages
Workers Sites i Pages to bezpłatna lekcja Edge Computing with Cloudflare Workers & Deno na CoddyKit. To lekcja 1 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Edge Computing with Cloudflare Workers & Deno, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Edge Computing with Cloudflare Workers & Deno zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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-appIntroducing 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.
Ucz się Edge Computing with Cloudflare Workers & Deno dzięki korepetycjom AI — za darmo
Pisz i uruchamiaj kod w przeglądarce, otrzymuj natychmiastową pomoc od korepetytora AI dostępnego 24/7 i kontynuuj naukę w sieci lub w aplikacji.
- Kursy
- 12
- Lekcje
- 47
Często zadawane pytania
Czy lekcja „Workers Sites i Pages” jest bezpłatna?
Tak — pełny tekst „Workers Sites i Pages” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Edge Computing with Cloudflare Workers & Deno, przejdź na CoddyKit PRO. Kurs Edge Computing with Cloudflare Workers & Deno zawiera 4 lekcji w sumie.
Co nauczysz się w „Workers Sites i Pages”?
Hostuj witryny statyczne i aplikacje jednostronicowe bezpośrednio na brzegu sieci Cloudflare za pomocą Workers Sites i Pages Ćwiczysz Edge Computing with Cloudflare Workers & Deno z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Edge Computing with Cloudflare Workers & Deno?
Nie wymagamy żadnego doświadczenia. Edge Computing with Cloudflare Workers & Deno w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 1 z 4.
Ile czasu zajmuje lekcja „Workers Sites i Pages”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Edge Computing with Cloudflare Workers & Deno?
Tak. Każda lekcja Edge Computing with Cloudflare Workers & Deno zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Workers Sites i Pages
- Integracja z frameworkami frontendowymi
- Proxy baz danych w Deno
- Renderowanie po stronie serwera na edge