https://htmx.org logo
Join Discord
Powered by
# htmx-general
  • g

    gorgeous-airport-54386

    03/22/2023, 10:44 AM
    It works, and you can do things that require large numbers of API calls to be collated since you have a place to cache the result for all users
  • f

    freezing-waitress-26396

    03/22/2023, 10:45 AM
    Oh yeah, simply didn't occur to me as a default way for htmx
  • f

    freezing-waitress-26396

    03/22/2023, 10:47 AM
    I mix both, mostly htmx queries the API directly, for specific things I query a different endpoint that returns markup the API isn't supposed to expose directly
  • f

    freezing-waitress-26396

    03/22/2023, 10:47 AM
    so, same thing
  • a

    adventurous-ocean-93733

    03/22/2023, 10:47 AM
    How does htmx query the api without the browser having the token?
  • g

    gorgeous-airport-54386

    03/22/2023, 10:48 AM
    You could add the auth header with
    htmx:beforeRequest
  • t

    tall-sundown-41732

    03/22/2023, 11:26 AM
    Hey everyone, is this a good place to get a bit of conceptual help? I am hitting a couple of roadblocks and it may be because I lack some theoretical knowledge about web stuff.
  • a

    adventurous-ocean-93733

    03/22/2023, 11:27 AM
    Yes
  • t

    tall-sundown-41732

    03/22/2023, 11:30 AM
    Great! I'm trying to do something that I'm not sure I should do. And this feels like a common pattern, so I'm also surprised I coudln't find anything in the HTMX docs about... Essentially, after doing a request to my backend (Flask/Python, in case it matters) I want to get the data back bit by bit and update it in real-time.
  • t

    tall-sundown-41732

    03/22/2023, 11:31 AM
    Is there any reason why this shouldn't work? The Flask docs seem to suggest I can stream data back, but when I put together a tiny example, I don't see the partial updates. I only see the new data after everything has been returned.
  • g

    gorgeous-airport-54386

    03/22/2023, 11:31 AM
    htmx buffers the whole response before swapping
  • g

    gorgeous-airport-54386

    03/22/2023, 11:32 AM
    because it's difficult to put a stream of html into an element
  • g

    gorgeous-airport-54386

    03/22/2023, 11:32 AM
    It might be supported in htmx 2
  • g

    gorgeous-airport-54386

    03/22/2023, 11:33 AM
    You can instead use websockets
  • g

    gorgeous-airport-54386

    03/22/2023, 11:33 AM
    Or Server-Sent Events
  • t

    tall-sundown-41732

    03/22/2023, 11:33 AM
    Between WS and SSE, any particular reasons for why I should pick one or the other?
  • g

    gorgeous-airport-54386

    03/22/2023, 11:34 AM
    WS is bidirectional, SSE is simpler to implement (since it's just a streaming HTTP response).
  • g

    gorgeous-airport-54386

    03/22/2023, 11:34 AM
    I handrolled SSE once and it was super easy, whereas I'd need a library for websockets
  • t

    tall-sundown-41732

    03/22/2023, 11:34 AM
    Unidirectional... from the backend to the client, right?
  • g

    gorgeous-airport-54386

    03/22/2023, 11:34 AM
    Yep
  • t

    tall-sundown-41732

    03/22/2023, 11:34 AM
    So, I could send partial updates from the backend..
  • t

    tall-sundown-41732

    03/22/2023, 11:34 AM
    In flask?
  • t

    tall-sundown-41732

    03/22/2023, 11:35 AM
    Any chance you have some code I could look at?
  • g

    gorgeous-airport-54386

    03/22/2023, 11:35 AM
    In Express.js
  • g

    gorgeous-airport-54386

    03/22/2023, 11:35 AM
    One sec
  • a

    adventurous-ocean-93733

    03/22/2023, 11:40 AM
    In case you haven’t seen the htmx extension: https://htmx.org/extensions/server-sent-events/
  • t

    tall-sundown-41732

    03/22/2023, 11:41 AM
    I did take a look at that web page.
  • t

    tall-sundown-41732

    03/22/2023, 11:42 AM
    Can't say I understood everything, but I'll digest it.
  • t

    tall-sundown-41732

    03/22/2023, 11:42 AM
    Does the backend usually need to do something specific/different to send the events?
  • g

    gorgeous-airport-54386

    03/22/2023, 11:42 AM
    It needs to use content type
    application/event-stream
1...107510761077...1146Latest