Optimizing Bluesky comments
Jack Platten
January 12, 2025
Having comments on my blog with Bluesky is pretty nice, but what's not so nice
is having to bring in the entire @atproto/api package. It seemingly can't be
tree shaken down via Vite, so you end up with a massive JS file for comments.
How massive is it? More than 700kB.
!screenshot of terminal, with the size of the bluesky comments file highlighted showing 700kB
It's kinda a lot, and as it is I had to tweak my Astro config to make Vite not
warn about this:
I wasn't a huge fan of this for a few reasons. One, that was a lot of unneeded
JS being delivered that I didn't need, and I had to modify a warning setting
which seemed less than ideal.
I had seen @atcute/client by Mary float across my
feed, and poked at it a bit, but only after I figured out how to make unauthenticated
requests with it did it become clear how much better it was going to make my
bundles.
Only took a little bit of modifying the work I had done using Emily Liu's example
to instead use atcute:
The unexpected benefit here is that @atproto/api didn't actually have all the
helper functions Emily needed for it to work, so there was a direct call to one
of the xrpc endpoints. Now that everything just uses rpc.get, it's a lot more
consistent and easier to follow.
I did have to add a few //@ts-expect-error sprinkled around, but they're all
guarded by typeguards so I'm not too worried.
Now instead of 700kB, my BlueskyComments.js is only 10kB. A vast improvement.
Thanks again to Emily for posting their code to begin with, and Mary for an
excellent suite of tooling that's much more compact than the full ATProto API.
Discussion in the ATmosphere