Workers Sites: Extending the Workers platform with our own serverless building blocks

Ashley Williams
8 min readintermediate
--
View Original

Overview

The article discusses the enhancements made to the Cloudflare Workers platform, specifically the introduction of Workers Sites, which allows developers to deploy static websites easily using the Wrangler CLI. It highlights the use of Workers KV to simulate a filesystem and the importance of caching strategies for static assets.

What You'll Learn

1

How to deploy static sites using Cloudflare Workers and Wrangler CLI

2

Why simulating a filesystem using Workers KV is beneficial for static asset management

3

How to implement effective caching strategies for static assets in Cloudflare Workers

Key Questions Answered

How can I deploy a static website using Cloudflare Workers?
You can deploy a static website using Cloudflare Workers by running the command 'wrangler init --site' to create a new project, configuring the 'wrangler.toml' file with your account details, and then publishing it with 'wrangler publish'. This process allows you to utilize Cloudflare's global network for your static assets.
What is the role of Workers KV in the Workers platform?
Workers KV acts as a secure key-value store that simulates a filesystem for Cloudflare Workers. It allows the storage and retrieval of static assets by mapping file paths to their content, enabling efficient access and management of static site resources.
How does caching work for static assets in Cloudflare Workers?
Caching for static assets in Cloudflare Workers is implemented through an asset manifest that maps filenames to content hashes. When a request is made, the Worker checks the cache first, reducing the need to read from Workers KV, thus improving performance by serving cached assets directly from the edge.
What challenges are addressed by the new Workers Sites feature?
The Workers Sites feature addresses the challenge of deploying static websites easily without needing a traditional filesystem. It allows developers to leverage Cloudflare's edge network while managing static assets efficiently using Workers KV and caching strategies.

Key Statistics & Figures

Number of cities in Cloudflare's global network
194
This extensive network allows for efficient deployment and access to static sites worldwide.
Number of countries with Cloudflare presence
90
This global reach enhances the performance and availability of deployed applications.

Technologies & Tools

Backend
Cloudflare Workers
Used to deploy and manage static sites and handle requests for assets.
Database
Workers Kv
Serves as a key-value store to simulate a filesystem for static asset management.
Tools
Wrangler CLI
Command-line tool used for deploying static sites to Cloudflare Workers.

Key Actionable Insights

1
Utilize the Wrangler CLI to streamline the deployment of static sites to Cloudflare Workers.
This approach simplifies the process of getting static content live on the web, making it accessible globally through Cloudflare's extensive network.
2
Implement caching strategies for your static assets to enhance performance and reduce latency.
By leveraging the asset manifest and edge caching, you can ensure that frequently accessed content is served quickly to users, improving the overall user experience.
3
Explore the flexibility of the Workers platform to adapt to new use cases.
Understanding the capabilities of Workers can inspire innovative applications and solutions that leverage edge computing effectively.

Common Pitfalls

1
Overcomplicating the deployment process by not utilizing the Wrangler CLI effectively.
Many developers may attempt to manually manage deployments, which can lead to errors and inefficiencies. Embracing the CLI tools provided can streamline the process and reduce potential issues.

Related Concepts

Edge Computing
Static Site Generation
Caching Strategies