Why do we need to write code on the client and the server?

Hi Everyone!

We get a lot of questions about the distinction between client and server code in Anvil. To help make it clearer why we often need to write code in two different places, I’ve written a short introduction to the client-server architecture of web apps.

If you have any further questions, feel free to ask them on this thread!

7 Likes

Thanks for the clear explanation. A small addition: you didn’t mention performance. Performance may also be a reason to process certain code on the server side. My CalcuDoku (special kind of sudoku) solver code was running remarkebly faster at the server side.

1 Like

thank you Brooke for your nice article
bu how to use Client code in Server code?
How to use variable defined in Client code in Server code?

You can send the variable as a parameter to the server function. Please read the docs

2 Likes

Also, a “client-side” module (as opposed to a form) can be imported and used in a server module as well as client-side. But it’s important to understand that it’s being loaded and run in two separate Python environments if you use it both client- and server-side. So you can’t use such a module to have a global variable that is accessible both client- and server-side, for instance.

3 Likes