-
-
Notifications
You must be signed in to change notification settings - Fork 192
Closed
Description
Someone proposed the creation of a "The Big Unlearning" guide in discord. I and others have also floated such a thing various times. I'm not the one to write it, but figured that we can start to dump/brainstorm ideas here for inclusion in such a doc.
Here's some things that I had to wrap my head around/learn
- SSE is HTTP so is compatible with all (is that true?) HTTP stuff.
- e.g. You can add gzip, brotli, zstd compression as you would for any http response - be it in your application (d* bad apple example does this) or in a proxy server (caddy, nginx, cloudflare etc). I documented a lot of that in this issue.
- D* does not just open one SSE connection that everything gets piped through from the server - like you might do with WebSockets. Each request is a new http request that happens to have SSE headers and can therefore return nothing (eg POST data), 1 message and close (request-reply pattern) or infinite responses (long-lived SSE connection). You could also, in theory, maintain multiple long-lived connections for different endpoints. If using http2+ it shouldn't really be an issue since, in theory, you could have infinite requests sharing the same multiplexed connection.
- this video and article really ought to be featured more prominently
- Dont be afraid of sending an entire document for morph/merging rather than more granular elements (in fact, it might even be better/more performant
- Its HOWL - you dont need any particular backend, let alone NATS/event-driven stuff. But its plays particularly well with such an approach (and NATS is just glorious compared to its alternatives)
- idiomoprh is the appropriate default for merge-fragments. Use it as much as you can, unless you're truly just appending/prepending a fragment somewhere - then it might be appropriate to change the
mergeMode. - You also dont need to specify the
data: selector #fooif the fragment contains an ID (as it should) - idiomorph will just find it and deal with it. - This all makes D* is particularly compatible with brownfield apps, as you dont need to modify the html templates as you would with something liek htmx (eg adding
hx-swap,hx-targetetc...). Just send the fragment with the ID and/ordata: selectorand it will work. - Should probably elaborate on this compared to
hx-boost
And some "collected wisdom" from discord:
10 commandments (and some of my own additions/elaborations)
- SSE is just HTTP response with ability to send 0- ♾️ chunks
- SSE it cost the same as any fetch.
- Yes its a framework, it is also a library.
- D*'s superpower/contribution to hypermedia is making signals easy to use declaratively
- But try not to use signals until you need them(theyre at the top of hypermedia maslow hierarchy of needs
- theyre most useful when the dom and its elements are stable and you just want to change the content (name, time, date, price etc...). Fragments are the Bricks of your house, they alone hold together and can last a while on their own but signals are the mortar than can flex and hold together your house when rain and wind comes. If you are building a simpler fire pit, bricks alone are fine... building a cathedral, you have well place mortar thoughtfully placed too much mortar and the whole thing collapses
- immediate vs retained mode (i believe immediate is essentially hypermedia/MPAs whereas signals are retained mode. Use each when appropriate?
- Don't put state in the wrong place (keep it on server - or at the very least in service worker proxy, not in a SPA)
- Don't over complicate it
- Hypermedia is faster than you think
- CSS and View Transitions hide any server work
- Just start coding with it, it's easier than you think
- :NotACult: but 🖕 JS
pepe
Metadata
Metadata
Assignees
Labels
No labels