Pages functions vs workers - the difference

Difference between Pages Functions and Workers (please correct me if I am wrong): - Pages Functions use an older version of Wrangler (version 3.101.0, which cannot be changed). Workers can use the latest version which is 4.x and supports the latest workerd with TLS support. - Pages Functions have limited logging; you would need to enable "Log stream" in Pages > Functions to see the logs, versus Workers which has the new "Worker Logs" that you can enable. - Pages Functions are not visible in the console under "Workers & Pages" – hence they can only be edited in your Integrated Development Environment. - Pages Functions use onRequest(context) and Cloudflare Workers use fetch(request, env, ctx) – I am not sure if they are interchangeable and which is better. - Pages Functions have automatic routes based on your /functions folder and have a built-in catch-all routes functionality. - Pages Functions and Workers plans are separate from Pages Plans. So even if you have a Pro Pages plan, that still gives you 10 milliseconds of function run time as opposed to 30 seconds (I am not clear about this one). - When you make changes to a Pages Function in your Integrated Development Environment, you need to push your entire repository (including your static website, along with your functions folder) to GitHub, and Pages will build it for you. You cannot push one Pages Function only, versus Workers, which can be pushed separately without needing to rebuild your project. - Pages Functions are automatically added to your existing domain and project, i.e., www.mysite.com/api/someFunction will just work. Versus a Worker will need some heavy lifting if you want it on the same domain and work alongside your other Pages Functions – I need clarity on this. - Rumor: Pages itself may be deprecated, moved, or renamed (may be hyperbole) but it feels like it. I will keep this updated mostly for my reference. Hoping @Walshy can comment.
7 Replies
Walshy
Walshy2w ago
1. This is a Pages CI vs Workers CI difference but yes 2. yep 3. expand? you can edit all the function things within the pages project 4. correct, not interchangeable and "better" is dealers choice. i'd say neither and using a proper router like hono 5. yep, workers approaches this differently 6. the plan stuff for pages was quite confusing. for functions, that used workers paid still, since, functions are just workers. zone-level plans only impacted ci stuff/domains, not anything functions related 7. if using workers assets you'd do the same unless you split that out into multiple workers. this seems normal to me though 8. workers shouldn't need any heavy lifting, you just use the routes system like normal. you could do mydomain.com/* or add a custom domain and then it'd be the same as pages, no extra work 9. rumor: eventually, yes. right now, all our investment is going into workers because that should be the way forward for everyone
Ricky U
Ricky UOP2w ago
Follow up qs: 1) Pages Functions: sorry i said console, i meant dashboard, you cant review the code in the dashboard ? 2) Hono doesn't see to gel with Pages functions, or atleast on my last attempt, could it be because of the older wrangler? 3) Agreed that the pricing is all to confusing for both, frankly im using Pro Pages+Argo and Paid Workers, not sure if there is any overlap or benefit here. 4) If you setup a new worker under the /functions directory with a .toml file with a entry point to index.js, when pushing to CF pages would PAGES pick up the worker as a function? --I would like my new workers to be on the same path as my current pages functions, i.e. domain.com/api/functionName. 5) The new workerd (wrangler 4.x) supports tls and net socket, hence mongodb drivers all now work, which is great, but I lost couple days with this using pages functions, it just doesn't work and i've figured it could be because wrangler is 3.18 (older version) but cant seem to force pages to use the latest one, Similar to how we can set a node var version, can we do the same with wrangler version for pages functions? 6) The npm create cloudflare now creates a simple worker by default with vite and without a .toml file (jsonc). All the docs and offocial video guides are all lost on newbs (they were created just a few months ago) and are all dated. Hence can we use flags to not use vite and use a toml file instead, for simple workers vite is not needed, or do we just remove it manually.. Thanks sir!
flashblaze
flashblaze2w ago
These are some great questions! @Walshy | Workers/Pages would really love if you can get back to these whenever possible
Walshy
Walshy2w ago
1. You cannot look at/edit Functions code in the dashboard no 2. Hono should be totally fine with Functions, used it myself before - I'd recommend opening another thread for that 3. Pro gives concurrent builds/more domains, argo is argo but doesn't really benefit Workers/Pages since there is no origin and then Workers Paid is obviously good for Workers/Functions 4. I wouldn't recommend making it under the functions dir, you can if you wish but i wouldn't recommend it. either way, no, it wouldn't be picked up as it'd be detected as a non-function 5. Question for Builds team - I'm not sure what options are available there today 6. err i was not aware that was using vite, you can just delete and make a wrangler config yeah - i'd recommend filing an issue on workers-sdk too - https://github.com/cloudflare/workers-sdk/issues
gdesmedt1
gdesmedt16d ago
This is really helping me as a noob, so thanks for these questions and answers! One thing I'm struggling to understand is
Can you run multiple "workers" in one "worker" - because you are able to run Svelte and a worker in 1 worker - can you hav emore workers in there? Or do you have run Svelte on Pages - and then link to multiple workers that are seperate for different things?
Sorry if that question makes no sense - but trying to make sense of the concept of "workers" vs "pages" - in my mind I have "pages are public or restricted pages that people will access and use and have a UI - and they call various "workers" to do various backend logic stuff" - so then when I hear I can run Svelte ON a worker - I'm like, ok, but where do I then run the "worker" for the backend logic, and if it's in the same "worker" - then how many of these workers can I have on a "worker" 🙂
Walshy
Walshy6d ago
I'm a bit confused but I'll say, Pages has only 1 Worker and you can design your app using as many or as few Workers as you wish e.g. you could use a single Worker for both front and backend, you could split those up - you could make your backend 12 different Workers for a very complex backend -- it's really all in your hands A Worker can bind to other Workers but it cannot like run a Worker in a Worker like spawning multiple vms on a machine
gdesmedt1
gdesmedt16d ago
ok - I think this is the part that's tripping me up
You could use a single Worker for both front and backend
so you can have 1 system, that has a front end on Svelte, and then the backend running your API's - and it's all in one worker... correct?

Did you find this page helpful?