So, your code gets deployed to hundreds of data centers, as does your storage. Requests are very cheap. Our free plan gets you millions of requests per month. WebSocket supports. So, you can choose, depending on the app that you're building, between an HTTP response and a WebSocket connection. We can do HDL rendering at edge, but we can do HDL parsing at edge, which we're going to get into in our example, and we have two distinct offerings for ways of having some application state or some storage that can be very quick for you, too.
So, before we get into building, I just want to cover some of the Cloudflare service terminology for those not familiar, because I'm going to be using their kind of official product names going forward. So, when I refer to Cloudflare workers, that's our serverless platform, so you deploy your code, which we would call a worker. It runs at edge, meaning it runs in all of our data centers, and it has the format of it takes in a request and it returns a response. We have a product called KV. That's our key value store that also runs at edge. It's very fast to read, since your data will, the value and your key will live at all of the data centers, but it is eventually consistent, meaning that if you update it, if you do it right, it takes a little while for it to propagate to all of the edge servers. We also have durable objects, which is another storage offering. These are persistent JavaScript objects, so they persist to disk, and they're just this one single instance, so they're not replicated to edge. So, they're a little bit slower reads, but they open up a whole slew of things that you can do pushing a lot of dynamic data. And then the last thing is we have a product called HTML Rewriter, and this is an HTML parser that runs at the edge, so you can not only render HTML, like markdown to HTML, which you've always been able to do, but you can actually scan the HTML and make dynamic changes. Anything that you would be changing, if else, with React, you can do that kind of stuff with our HTML Rewriter.
So, a little food for thought before we get into it. If you were asked to build a blog and you needed to be really fast, really perform it, but you also wanted to have some of these nice WordPress features, like a popular post section, a like counter on each post, or the ability to add comments, what tool set would you reach for? Would you instantly go for a full dynamic app, like a WordPress instance, or some kind of CMS? Or would you try to put something together, maybe with a static site host, plus a few serverless functions and kind of try to stitch it together? So, our workflow that we're going to be using today is take any static site template, so this could be like Jekyll or Hugo, Eleventy, Gatsby, anything that produces a bunch of HTML files. You can even just write the HTML files yourself, it really doesn't matter. Install the Cloudflare CLI, which is called Wrangler, and then we're going to initialize a worker's site project, which I'll get into in the next slide, and then we're going to go ahead and publish it.
So, what is worker's site? So, when you think about hosting these static sites, like GitHub Pages, Netlify, Cloudflare Pages, the basic idea is that you take your GitHub project or your Bitbucket project, and you point it at one of these services, and somehow, behind the scenes, the service runs a build, grabs all of your static sites, and starts a web server, and now when you go to that URL, it routes you. You know, just behind the scenes, it's doing everything you'd expect it to, right? And so, there's a lot of ways that you can accomplish this, but one way you could do it, if you wanted to build your own experience, would be using worker sites. And so, what this will do is, it'll take that folder full of HTML files, and it'll stick each HTML file in Cloudflare KV, our Key Value Store. And so, if you have an about.html, it would make a new entry in KV, the title would be about.html, and the value would be the actual HTML inside that file. And it'll do that for all of your files, and so what you'll end up with is, a bunch of KV stores. Each one's name is the file name, and the value is the HTML itself, and then it'll also generate a simple JavaScript worker, which will just listen for all incoming traffic, pluck out that route, that file name, and go fetch it from KV and serve it. And so you can see, after we just, I grabbed that 11T base project, I ran worker sites on it, and then I deployed it, and you can see I have, this is my KV dashboard. And on my KV dashboard, I can see all of my little file names as the keys, and the values are actual raw HTML, or CSS, or XML. And then, accompanying that, I get this very minimal worker.
Comments