re-frame

liebs 2024-05-08T10:30:41.939179Z

I have about twenty or so static files on the server the contents of which eventually end up in my app-db. I am curious whether it's a reasonable approach to build up my initial app state on the server, serialize it, and then send it over the wire alongside my bundled JS? Or should I prefer making ad-hoc fetch requests to grab the bits and pieces as I need them? I'm currently using this latter approach but it feels a little overcomplicated for what is a more-or-less simple application.

p-himik 2024-05-08T10:31:49.800169Z

Depends largely on the size of the data and, I guess, on the connection quality of your users.

liebs 2024-05-08T10:34:32.650939Z

Most of them are fairly small, but I guess if I were to make a big initial request of the ensemble, it wouldn't be that much different in practice than simply having them all in the bundle to begin with, and then the bundle size is an issue. Well, as long as there are no other obvious concerns, it's something to think about.

p-himik 2024-05-08T10:35:25.359089Z

"Fairly small" is not an objective metric. :) For me, it's up to 1 MB. For others, it can be 100 kB or 100 MB.

liebs 2024-05-08T10:40:22.441549Z

Thanks for the frame of reference. That's helpful. They're each smaller than 100kb for sure.

p-himik 2024-05-08T10:42:06.605449Z

So around 2 MB total. But you should check the compressed size, not the raw size.

👍🏻 1
thheller 2024-05-08T11:15:10.307129Z

IMHO data should stay data and not become part of a .js file. you can however put the data directly into the HTML in some way, so that no extra request is required.

➕ 1
p-himik 2024-05-08T11:19:25.917099Z

As far as I'm aware, where you put it doesn't make any practical difference, at least not for the overall UX. However, putting a lot of data right into HTML can make things worse for the server if the website ends up being crawled frequently.

doug kirk 2024-05-08T14:45:23.826389Z

I'd fire a single dispatch to fetch all of it in a bundle when the app starts. On the back-end, have an endpoint that will call all the necessary functions or simply assemble the expected payload in the correct format and send it all at once. That way you get fast initial appearance in your app, the data transfers in the background and is set into app-db when it arrives. Makes the app seem more "progressive", as Google likes to call those style apps.