Repository navigation
|
Sorry if my question makes nonsense. I am working on a Remix app, Remix is helping me a lot!!! Since I am working with a public API from the loaders and actions, I realised that most of my routes are not actually "private" and use server resources. I wonder if there is a way to define if the loader when revalidating and/or the action should be run in the front end when the developer considers it. I noticed that most of the loader/action logic is placed in React Router (client), the fact that the fire the server is a Remix part. |
Replies: 3 comments 3 replies
|
No, Remix loader and action functions always run server side and at least right now there’s no way to change that. And even if you fetch a separate API using the loader/action server side would let you remove extra data or combine data from requests making the data the user download smaller than if you fetched the API client side. |
|
For our use case, which I don't think would be niche/edge case, it would help a lot to be able to mark a loader or action as client-safe, or alternatively export a If this feature was added, I would expect Remix to only run the loader client side once JS has loaded and fall back to the server side if there are any JS failures. Our use case is that most of our loaders and actions are connecting to a REST API in a way that we can reveal the token to users. The API (the Firestore REST API) is very fast and distributed. Of course it makes sense to do the initial API calls server side in order to render the page, but subsequent calls would be faster if done client side connecting direct to the Firestore REST API. If our Remix application was deployed to the edge in a way that was as fast and as close to the users as the Firestore API is, then perhaps there would not be a significant impact, but if our Remix instance was running further away from the user that the Firestore API then it is going to slow things down. I have just deployed our application with Remix to a Netlify preview environment with Our API calls via Remix are 284-731ms whereas for the client side version they were 37-85ms. When running traceroute I think this is because the Netlify preview environment is based in the US (I'm in the UK) so I am guessing this won't be as big an issue if I configure it correctly or it was on a production environment, but not all users of Remix would be able to deploy to the edge (or have a Remix instance that was as fast as their API) so would still face this issue. One thought I'd had was to look in to the code in remix/react-router that is calling the loader function client side and see if there's a way for us to override this to call a |
No, Remix loader and action functions always run server side and at least right now there’s no way to change that.
And even if you fetch a separate API using the loader/action server side would let you remove extra data or combine data from requests making the data the user download smaller than if you fetched the API client side.