#Perf gains from using .server file

1 messages · Page 1 of 1 (latest)

warm cloak
#

What is the perf gains from using a .server extension? I'm wondering because I want to make an object that is accessible by the server and the client, and it makes sense to have it located in the file that holds my server code.

That being said, everything but this object is only run on the server, and this object is the only thing that needs to be on both the server and the client, should I create a new file for that? Is it worth it? Or should I just rename my file to exclude the server extension?

sly leaf
#

The .server extension tells the Remix compiler to exclude that file from the client bundle

Most of the time the compiler should be able to infer if a module is server-only, client-only or shared, but by using this extension you give it a hint about that

This can be useful if, for some reason, the compiler fails to infer it and is trying to include in the client bundle a server-only file, like a file accessing env variables or a file using Node.js modules like fs

warm cloak
#

makes sense. So if I have one object that is used on the client within this file, and the rest of the file isn't used on the client, will remix be smart enough to only have that one object be compiled to the client?

sly leaf
#

if the file has the .server it will not add it to the client bundle, but if you mix server and client exports from a file without the .server (or .client) extension it should be smart enough to remove the server-only exports from the module on the client-side bundle