Forum Moderators: phranque

Message Too Old, No Replies

Ideas for using "workers"

         

csdude55

9:12 pm on Nov 22, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm setting up Cloudflare, and they have an option to create "workers". Here's a the "hello world" example they give:

/**
* Welcome to Cloudflare Workers! This is your first worker.
*
* - Run "npm run dev" in your terminal to start a development server
* - Open a browser tab at http://localhost:8787/ to see your worker in action
* - Run "npm run deploy" to publish your worker
*
* Learn more at https://developers.cloudflare.com/workers/
*/

export default {
async fetch(request, env, ctx) {
return new Response('Hello World!');
},
};


This is all good and interesting, but how can I use it in the real world?

csdude55

6:29 am on Nov 25, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I asked on the Cloudflare forum, and they gave a few examples of sites using workers but I honestly couldn't see how they were better than a simple form and server side processing. They certainly didn't seem faster on my end, anyway!

In theory, though, I could potentially replace Ajax scripts with a worker. That seems like a practical use, anyway, but I'm not sure if it's any better or worth rebuilding my Ajax scripts for it.

graeme_p

11:02 am on Nov 25, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It IS server side processing and it is supposed to replace your backend - they say it is "serverless"

lucy24

6:03 pm on Nov 25, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It IS server side processing ... they say it is "serverless"
You mean, it's like the washerless faucet a plumber once tried to sell me on. It doesn't use a washer; instead it’s got “a rubber thing”.

Shrug.

csdude55

7:12 pm on Nov 25, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Haha, @Lucy24! That sounds about right.

@graeme_p, that was kind of my takeaway when I was reading through examples: it seems like a harder, more limited way to do the same thing that I'm already doing. I THINK that the only real difference is that it would use one HTTP request? But it's not clear if that means one-per-page, one-per-user, or one-total.

graeme_p

1:24 pm on Nov 29, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



@lucy24 - nice comparison.

@csdude55 not sure with cloudflare workers in particular. They might be faster for users not geographically close to your server by reducing latency if they run on the nearest cloudflare server. The general trade off with serverless is that you trade control, low cost and flexibility for easy scaling and not having to admin a server. Not something I am fond of.

csdude55

6:19 pm on Nov 29, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I started watching Silicon Valley, and I'm in the 5th season where they're working on a "serverless internet". The concept is hilariously absurd to people like us, but it's ironic that I've been researching "serverless" coding at the same time! LOL

I've given up on using this for now, though. Maybe in a few years it will be worth revisiting.