| ▲ | nprateem 3 days ago | ||||||||||||||||||||||
Datastar looks interesting, but their guide on how to redirect a user is a joke. async def redirect_from_backend():
LOL, they really think it's a good use of server resources to sleep so the client doesn't have to.[1] https://data-star.dev/how_tos/redirect_the_page_from_the_bac... | |||||||||||||||||||||||
| ▲ | JSR_FDED 3 days ago | parent | next [-] | ||||||||||||||||||||||
One of the things I had to wrap my head around was the whole async server style of programming. I learned that doing a sleep on the server consumes essentially zero resources. The thread goes to sleep and wakes up when the timer expires. In the meantime the server can handle other requests unhindered. You can have hundreds or thousands of these threads at the same time - serving requests, waiting for IO, etc. It’s not like synchronous servers e.g. Flask with Gunicorn (in the Python world) where you have a few pre-forked server processes. In that case it would be a waste to prevent one of those processes from serving other requests while sleeping, I agree. Ultimately it’s cool though to be able to control the client from the backend asynchronously, updating signals (think of them as a kind of special front-end variable with superpowers) when something on the backend happens, or updating the client’s DOM, or running scripts. | |||||||||||||||||||||||
| |||||||||||||||||||||||
| ▲ | gazpachoking 2 days ago | parent | prev [-] | ||||||||||||||||||||||
That's a contrived example to show how you can redirect from the backend (and the sleep is to make it easy to see it working.) It isn't a recommendation that you should do it exactly that way. | |||||||||||||||||||||||