Live data from Hacker News

Cloudflare Workers: Run JavaScript Service Workers at the Edge

blog.cloudflare.com

51–60 of 134 posts

Re: Cloudflare Workers: Run JavaScript Service Workers at the Edge

#51
post #37

This is really cool...but why ?

I worked for an analytics company at one point and we generated impression IDs server side (you'd be surprised how broken client-side JS randomness can be) and included them in our loader. If we had been using CloudFlare I would have put our loader directly into this service worker so that we could shave a few more milliseconds off our intial response time, so that we could get to our cached JS faster. So yeah, if yo…

Ah, that makes more sense. Thanks!

Re: Cloudflare Workers: Run JavaScript Service Workers at the Edge

#53
post #34

This is really cool...but why ?

I thought of a few use cases... A more granular way to block requests than what cloudflare provides (IP, BGP AS, country) Tokenizing credit cards at the edge if you have a payment provider that supports that, and are using CF's PCI compliant environment. Injecting a unique ID into requests for log correlation. You get collisions if you do this via browser javascript for various reasons. I'm assuming v8 has a better M…

Also some good use cases. :)

Re: Cloudflare Workers: Run JavaScript Service Workers at the Edge

#54
post #46

This is probably the best annoucement of a new feature I have ever read. It makes an analogy to an existing technology. It provides a clear description of the new feature. It provides clear examples of how to use the new feature with a link to a sandbox so you can run and modify the examples. And it explains the thought process behind the implementation. In additon, I didn't notice a single typo, spelling or grammar…

Daww, thanks!

I wish I'd included more images and diagrams in the post, but I'm generally terrible at coming up with those.

I also wish we'd been able to enable it in production for everyone immediately... but with a change this big we need to be cautious.

Re: Cloudflare Workers: Run JavaScript Service Workers at the Edge

#55
post #13

Earlier quoted context omitted.

Will there be any limits on memory/execution time etc like with AWS Lambda?

Yes. Currently you get at most 50ms CPU time per request, and memory usage of your Javascript VM is limited to 128MB. These numbers may change before launch. In practice, though, a typical script probably uses much less than 1ms of CPU time per request and probably needs only a couple megs of RAM. Because we're applying limits on the level of a V8 Isolate, not on an OS process, the limits go a lot further. Keep in mi…

What happens if the limits are reached? Does the end user get an error or does the request proceed as it would without the script?

Re: Cloudflare Workers: Run JavaScript Service Workers at the Edge

#56
post #2

Hey all! This is my project at Cloudflare. (You may remember me as the tech lead of Sandstorm.io and Cap'n Proto.) Happy to answer questions!

Hey Kenton, should've guessed you were behind this. Lovely design, great work.

I'd be curious to learn more about the implementation (did you lift the existing SW implementation from blink somehow, or reimplement it)?

Re: Cloudflare Workers: Run JavaScript Service Workers at the Edge

#57
post #2

Hey all! This is my project at Cloudflare. (You may remember me as the tech lead of Sandstorm.io and Cap'n Proto.) Happy to answer questions!

Hey Kenton, should've guessed you were behind this. Lovely design, great work. I'd be curious to learn more about the implementation (did you lift the existing SW implementation from blink somehow, or reimplement it)?

PPS - it is probably too late for this, but one of the last things I worked on at Google was Gin:

https://chromium.googlesource.com/chromium/src.git/+/lkgr/gi...

A bindings layer for v8 that was specifically intended to make implementing web-style APIs outside of Blink easier. At the time at least, refactoring things like SW out of Blink was ~impossible.

Re: Cloudflare Workers: Run JavaScript Service Workers at the Edge

#58
post #20

Seems like this plus the Cloudflare Apps could yield some interesting projects.

Yup. :-)

This seems like it has a ton of potential. I'm already thinking of the possibilities for my own Cloudflare-proxied sites.

I hope it's not priced too harshly. Hopefully an added monthly flat rate rather than per-request pricing?

Re: Cloudflare Workers: Run JavaScript Service Workers at the Edge

#59

offtopic: can cloudflare be used as a CDN for just assets? The cloudflare docs talk only about using it as CDN for an entire site.

Technically, yes, but as I understand it, they frown upon it and could potentially terminate your account. See this section of their ToS (https://www.cloudflare.com/terms/):

>SECTION 10: LIMITATION ON NON-HTML CACHING

>You acknowledge that Cloudflare’s Service is offered as a platform to cache and serve web pages and websites and is not offered for other purposes, such as remote storage. Accordingly, you understand and agree to use the Service solely for the purpose of hosting and serving web pages as viewed through a web browser or other application and the Hypertext Markup Language (HTML) protocol or other equivalent technology. Cloudflare’s Service is also a shared web caching service, which means a number of customers’ websites are cached from the same server. To ensure that Cloudflare’s Service is reliable and available for the greatest number of users, a customer’s usage cannot adversely affect the performance of other customers’ sites. Additionally, the purpose of Cloudflare’s Service is to proxy web content, not store data. Using an account primarily as an online storage space, including the storage or caching of a disproportionate percentage of pictures, movies, audio files, or other non-HTML content, is prohibited. You further agree that if, at Cloudflare’s sole discretion, you are deemed to have violated this section, or if Cloudflare, in its sole discretion, deems it necessary due to excessive burden or potential adverse impact on Cloudflare’s systems, potential adverse impact on other users, server processing power, server memory, abuse controls, or other reasons, Cloudflare may suspend or terminate your account without notice to or liability to you.

I think in practice, unless you have a very popular website or are abusing it in some way, they probably wouldn't care or even notice. But you'd still be taking a gamble.

(I don't work at Cloudflare though so take whatever I say with a grain of salt.)

Re: Cloudflare Workers: Run JavaScript Service Workers at the Edge

#60
post #2

Hey all! This is my project at Cloudflare. (You may remember me as the tech lead of Sandstorm.io and Cap'n Proto.) Happy to answer questions!

The blog post mentions WebAssembly support in V8, but I can't get it to work in the playground. Coming later?
Post reply on HN