Skip to content

[SDK] Client vs Server

FTCHD edited this page Jul 13, 2024 · 2 revisions

If you create a new typescript file to group your functions, and import it in your Inspector, the functions you call inside the Inspector will run on the client. In most cases that's exactly what you want, processing should be offloaded to the client as often as possible.

You can do a lot of things on the client today, even downloading Youtube videos to the browser and converting them to GIFs without touching the server, see the GIF Template for example.

However, sometimes you want to run code on the server — usually when a package cannot run on the client.

To do this, simply create a new file (let's call it server.ts, but you can give it any name you want) in the same directory as your existing template files. Then annotate the file with use server at the top. This convention tells NextJS to run all functions in this file on the server. Now you can import these functions in your Inspector and be sure they will run on the server.