Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Cloudflare working on Cloudflare Pages, for deploying and hosting JAMstack (twitter.com/wongmjane)
158 points by nilsandrey on Dec 6, 2020 | hide | past | favorite | 36 comments


For the last couple months, I've used Cloudflare Workers Sites to host one of my static sites, and I'm planning to migrate several more onto it. For those who don't know, Cloudflare Workers is their service that answers web queries by running server-side javascript that you've uploaded. It also comes with Workers KV, a very fast key-value storage database (like redis) that the server-side javascript can query.

So then, they said why not just upload your static site into the KV database, where the key might be "/index.html" and the value is the html content of that page. Then have a short javascript that reads from that KV and returns the requested page. They wrote some client-side scripts to simplify the uploading, and Workers Sites was born!

I love how your content is automatically replicated to all of their datacenters and loads super-fast from everywhere in the world. I also love that it's really cheap.

But the downside is how some features in Cloudflare's control panel don't work if you're hosting your static site this way. For example, I wanted to use the Page Rules to redirect /page1.html to /page2.html. I also wanted to use Page Rules to set browser caching for *.jpg files. But it turns out that Cloudflare Workers execute code before the Page Rules feature does, so it doesn't work! I had to solve both issues by changing their default javascript to build in redirects and browser caching manually. Not too hard, but annoying.


> I love how your content is automatically replicated to all of their datacenters

Well, it feels like it's automatically replicated, but your KV content is usually only stored in a few select datacenters until it becomes popular (and is then available on all DCs). This process is usually fairly quick (<50ms for a 10mb file, based on my testing from about a year ago) so it's almost imperceivable.

https://developers.cloudflare.com/workers/learning/how-kv-wo...

> It is optimized for these high-read applications, only reaching its full performance when data is being frequently read. Very infrequently read values are stored centrally, while more popular values are maintained in all of our data centers around the world.


Exactly. Little more clarification here though I think...

Flexibility of Cloudflare KV reads in general still yield quick enough results and make doing a quick and dirty cache a pretty good use case IMHO.

But Worker Sites specifically also use the Cloudflare Worker Cache runtime API — aka, per each POP, first reads of a route (index.html, blah.css, cat.jpg) are from KV and THEN cached indefinitely cutting that time to like 10ms.

This is taken then even further by using ETAG matching to make BrowserTTL indefinite (304s not 200s) on all assets until cleared cutting repeat visitors (regardless of POP) to basically nothing. Though .html for some reason doesn’t respect this (I think...).

Which to me is a GREAT deal!

Cache Object: https://developers.cloudflare.com/workers/runtime-apis/cache

Asset Mapper: https://github.com/cloudflare/kv-asset-handler/blob/master/s...

Lines 181 and 224


You can link to specific lines on GitHub by clicking the line number, then the ellipses, then 'copy permalink' (you can also shift-click to select multiple lines). It also links to the current HEAD commit so the code won't change on you later on.


Thanks! Was mobile can couldn’t figure out


I was thinking about doing the same recently. The big thing I wanted to test was the way they hide Worker spin up in the latency of the TLS negotiation.


Wouldn’t Wordpress + cdn basically give the same performance but with more functionality.

The only time the request needs to hit the origin is if nobody fetched the page.


Depends on what you mean by Wordpress+cdn. If your CDN is only caching your css and jpg files, then every page load still has to go back to your main server and talk to your database. This is how "standard" Cloudflare caching works. It's pretty good, but a page load from Australia would still have to travel all the way to your PHP+MySQL server in the US and back again.

To speed it up further, you can tell Cloudflare to cache your HTML pages. Now you've eliminated that round-the-world trip (for most visitors), but you've also lost some of the dynamicness of your site. At that point, you're basically building a static site by different means.


There's now an official Cloudflare Wordpress plugin that makes sites hosted this way incredibly fast.

In the confidence it caches the HTML, and the plugin triggers a CDN purge when the HTML changes

Coupled with Cloudflare's standards support (TLS 1.2, H2, H3), and their image optimisation services it's really great for performance.

Just got to remember to disable many of the WP 'speed optimisation' plugins that may be installed as they actually can cause more speed issues.


It all depends...

But probably not against a static page.

Wordpress is still PHP and a Database and whatever crazy plugins, templates and front end builders are involved.

Depending on how much JAM you have in your STACK, your site/app may or may perform better than WP.

I build a ton of sites in Jekyll, which are static sites and not JAMSTACK. The two get conflated.


Assuming you leverage the KV store for some things that are read-write or very dynamic, it should perform better.


Cloudflare already had the ability to host static pages on the edge with Workers Sites [1] but it required a paid subscription to Workers KV. They recently introduced a free tier for that [2], so Cloudflare Pages seems like a packaged up service with CI/CD added to the mix.

[1] https://developers.cloudflare.com/workers/platform/sites

[2] https://blog.cloudflare.com/workers-kv-free-tier/


Thanks for those links. I'm commenting so I can read them later :-)


Meta: You can click "favorite" on comments (and posts) and they'll be bookmarked in your HN account.


Oh wow. I never realized if I clicked into a comment I could favorite it. Thank you!


Wow, thanks for that! Had no idea.


also, the subscription was only $5


I've been embracing Cloudflare workers for more and more small websites and APIs, so much so that I ended up writing a small Koa/Express-like framework for it to make it more similar to 'normal' Node/Deno development [0]. Currently working on a starter template [1].

Cloudflare Pages sounds like a competitor to Netlify/Vercel mostly - paired with Workers it makes it very compelling. Slowly it's becoming a one-stop shop for me for small-medium projects that don't require any real compute.

[0]: https://github.com/gzuidhof/sunder [1]: https://github.com/gzuidhof/sunder-worker-template


I was literally just thinking about this yesterday, and am so excited! CF Workers already run at the edge and have a globally distributed kv store... you could use this coupled with Workers and KV to run an entire site along with data storage fully on the CF edge. That would get ridiculously low latency, automatic https with termination in the same DC as the compute (whereas with Netlify you either use their CDN and https or you run it thru CF and have 2 hops), and the ability to run lambdas in multiple languages with CF workers. I’m going to have to give this a try as soon as it’s available.


After much digging Jamstack is Js, APIs, and Markup--page renderer as far as I can tell.


That's right. The purpose of JAMstack is to take client rendered websites (sites built with React, Angular, etc) and pre-compile the views to be more like static webpages. It is typically faster for the user because the client side framework doesn't have to be downloaded and a lot of the layout and rendering computation was done before it was even deployed to the server. There are some pros/cons of course, and I'm oversimplifying a little, but hopefully this helps explain the basic concept.


So what's the thought process for choosing between that and cached dynamic pages? First visitor doesn't have to pay latency--serving a stale page while caching new one also works.


Download once, cry once IMO.


Thanks. I went as deep as their jamstack.org homepage, their "What is Jamstack" page and their "Glossary" page, failed to find the answer, and gave up.


This sounds like bad news for vercel and netlify, maybe a little less so for firebase.

https://pages.cloudflare-docs.workers.dev/pages/migrations


IMO: Cloudflare Workers are far superior but there are basically no frameworks to really leverage the power of all that tech.

If you had a next.js app why on earth would you NOT use Vercel thinking long term.

For Cloudflare, yeah a static site, configure some sort of basic SSR demos, a million Cloudflare code samples, but there’s no REAL starting point for full blown application development beyond going custom.

Coolest I have seen is Flarereact.

Netflify on the hand offers very little beyond insanely easy to use and a ton of developer promotion.


Is it? At least for Vercel they have robust support for NextJS/server side rendering having made the framework; the closest thing in Cloudflare as far as I know is Flareact [1] which as far as I can tell still has a long way to go before it's really feature-comparable and as battle-tested as NextJS.

For hosting a simple static/create-react-app-style web app, there's an overwhelming number of options for that already.

[1] https://github.com/flareact/flareact


Didn’t read this before commenting but you are exactly right.

There is NO good starting point for developers beyond snippets.

- Vercel as a framework they can modify around their platform

- Netlify is just easy to use and welcoming / friendly / not scary

- Cloudflare has code snippets... I expect this to change overtime as more migrate to Serverless but Cloudflare is like Serverless 2.0 (Durable Objects, runtime APIs) while everyone is building for 1.0 (quick cache clearing and server less functions).

Has been a couple years and still nothing I think.

The link on this post is cool to compete with Netlify and eat up all those small simple static sites but we developers really need a bit more of an ecosystem for app development (framework)


Their proposed UI is basically straight copied from Netlify.


I've played around with JAMstack - I've used Gatsby + Netlify to host/deploy a static site generator. It works surprisingly well and has lot of JS based feature you wouldn't expect from a 'static' site like forms, uploads etc.

but I feel that as it matures, there are no prizes to being an early adopter - it looks like it's getting better and easier to use and a lot of features that you had to code for in the past become configurations. So I am still in 'wait and see mode'.


Is the web page economy larger than app? These JAM stuff are out of control.

My theory is that more people coming to tech industry, and the base of pyramid is web pages up to web apps. Because all people want to have their personal site and blog. Tiny amount of people want to build application; it's surely harder. Numbers of app makers are just a few.

Tech community on social media is flood with tech that's for building these pages. And when people are hooked, they want to use this hammer for everything.


I would say it is much larger. From what I understand, many many websites can be completely functional as static pages with a few forms here and there.


I'm hoping this issue (https://github.com/cloudflare/wrangler/issues/1553) is addressed by the time they release Pages :( Excited for Pages however!


Here are more details and a beta signup form that we have just launched: https://blog.cloudflare.com/cloudflare-pages/


What is Cloudflare's content policy today? In the last few years they abandoned their prior commitment to free speech and decided to start deplatforming paying customers (https://blog.cloudflare.com/tag/freedom-of-speech/). As someone who cares deeply about protecting practical, real-life access that allows people to exercise their right to free speech meaningfully, it's important that platform and infrastructure providers also maintain a pro-free-speech stance. If Cloudflare is not that, I don't see why I would trust them with even more power and even more control over access to content on the Internet.


Available for free until Cloudflare decides that you are in violation of your their terms of service because you wore a MAGA hat (seriously lame) or expressed doubt about vaccines, after which it won't be available to you for love or for money.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: