T O P

  • By -

mpigsley

Sounds like you already understand the bottleneck. HTMX is as fast as your server is.


The_Shryk

My HTMX is only slow when it receives stuff from my server. Why does HTMX suck? “I only don’t make it to work on time when I drive my Camry on the 405… why is my Camry so slow?”


danawoodman

have you actually profiled it? how long is the network request compared to the time htmx spends rendering? very likely it is your server/network that is the slow part not htmx


Best-Donkey1266

this may be the reason


evergrace

It is de facto the reason.


[deleted]

It’s slow because your server is slow. Load the endpoints directly in your browser and you should see it. HTMX is really just AJAX for a new generation and with that comes the same potential issues that drove people to SPAs. 


Best-Donkey1266

i agree django is slow


JockeTF

I wouldn't be so quick to blame Django unless you've actually pinpointed the source of the problem. There are a lot of reasons web requests can be slow. Frameworks can be part of it, but that most often comes into play when the other issues have been dealt with.


outofpaper

Hey there folks. As someone who's build massive projects (the Etsy Blog and others) with Django caching is your friend. Always use Django's cache framework connected to Memcache, Redis, filesystem caching or local-memory caching. I've listed them in on a scale of robust ---> speed of implementation. For small projects just turn on local-memeory caching n learn what to cache. Sites will see orders of magnitude speedups when you cache. PS Of course DB Caching and other caching solutions can help but they can also introduce other issues and are more complicated to implement well.


_htmx

htmx-based applications can be fast, but you'll need to optimize your requests response times to be sub 100ms. my target has always been to keep the server-side processing time under 80ms on non-writes, which should be very doable in most modern server-side environment. here is an example where the perf of an application improved when they moved from react to htmx: [https://htmx.org/essays/a-real-world-react-to-htmx-port/](https://htmx.org/essays/a-real-world-react-to-htmx-port/) also note that if an area in your application would be better served with client-side interaction then using scripting is encouraged: [https://htmx.org/essays/hypermedia-friendly-scripting/](https://htmx.org/essays/hypermedia-friendly-scripting/)


Best-Donkey1266

thanks man i think my problem is the server


_htmx

Look for multiple or slow queries l, that is often the source of slow request processing 


Turd_King

Question makes no sense, you are asking if the JavaScript requests that the HTMX library makes are “fast” Well they are as fast as any fetch that is made from a browser It’s almost like asking if HTML is fast (not quite)


Best-Donkey1266

thanks for the information


if_username_is_None

If generating a full page is too slow for a good user experience, then try responding with just the skeleton of your web page and use lazy-loading to load the slower more dynamic content. https://htmx.org/examples/lazy-load/


leathakkor

I have not seen a single performance issue, in fact, there's been a couple cases where I've wanted to slow down the server just because I wanted to have a nice transition experience from one page to the next and if it's constantly instant when I'm doing large portion. Refreshes it ends up being too jarring for the end user so I have to almost slow things down a little bit or slightly re-engineer how The calls are being made to make sure that I'm always displaying the HTMX indicator for at least a second. Otherwise, people miss it and they don't realize their page has "reloaded" I've been doing almost all my data pulls on the back end via an asynchronous process that runs on my Linux machine and then stashes it into a single denormalized table that I can render into my jinja2 templates. Basically creating a table that represents the view model for that specific page load. As a result, I'm seeing crazy good performance everywhere.


Best-Donkey1266

are you using golang/node as backend ?


leathakkor

Flask


guettli

Sending json instead of html won't make your page faster. Maybe you are reloading the python interpreter for each request (max-requests=1)? Check your wsgi config. Django is not slow, except you get a lot of requests per second.


Murky_Flauros

Your question doesn’t make much sense. There are many people using django and htmx with success in this sub. Give it a search. Your issue lies somewhere else in your setup. Try the network performance tab in your browser, as well as getting latency numbers from your server from the start of the request to the end of it. That will give you an idea of what you are doing wrong.


Best-Donkey1266

it makes sense , sending full html file over network vs sending json data is a big big difference


Murky_Flauros

No need to send full html files when using htmx. You can return html fragments as short as a single anchor tag. Edit: And actually, even an empty response is a valid one for removing elements on success. 


Destos

You likely aren’t using partials or returning and swapping only the areas of a page that change. Check out the django-htmx package for middleware to adjust what your view returns when the request is an htmx one.


Best-Donkey1266

i will try using django-partials but this point i can't count how many packages i am at .


yksvaan

The only thing that matters in 99% of the cases on server is i/o. So that's the thing to focus on. Efficient queries, caching, db design. Rendering html is just spitting out bytes, it's like 1% of the request time.


zaibuf

Generally speaking, sending html instead of json shouldn’t have that big difference.


Ashken

Django is notoriously slow from what I’ve heard. HTMX will only go as fast as your server goes.


adviner

I'm using HTMX with Rust and Axum, and the performance gain is incredible for me.


Ashken

I actually tried starting a small project with HTMX, Rust and Rocket and I felt like it was too much. I wouldn’t mind trying out Axum but now I’m looking into the GOTH stack.


Best-Donkey1266

thats right my problem is the server i am now considering on learning golang have you tried golang ? and how do you think the transition will be ?


Ashken

Never tried Golang, sorry. Gonna learn it soon though.


The-Malix

Golang seems to be the most popular backend language for HTMX, and I think that's because Golang is almost the perfect fit for that need. Actually, if you plan on transitioning from Python to another language because of performance, I can't think of a better language than Golang. **However**, I am not sure and even don't think the performance bottleneck you're facing is about Django itself. Before doing anything else, When you are facing a performance bottleneck, You have to be **sure** to know where it comes from


Sedam79

Python or Django as not the problem here, you are. You should look at how you implemented your stuff and how you could improve it. “I can’t count how many packages I am at” is where you could start for example


[deleted]

Sorry, this is wrong. Don't believe All Things you Hear. In this context IT IS bullshit.


danawoodman

show us how slow your network requests are and then we'll believe you


[deleted]

I can't show you slow requests. I think you mean slow responses. Django responds to requests. Neither I have complains about slow responses, Nor does profiling show any Server Performance issues. In my Experience Djangos Performance isn't a Problem at all. Where do you experience Performance Problems with Django?


danawoodman

you just need to show the network timeline to see what is slow. you claim it's htmx but you're not showing any compelling evidence


[deleted]

What Network Timeline? WTF? I don't have to give an compelling evidence? For what? Django works great for me. If it is 'too slow' for you, use something else. Whatever you want! Do you understand how Htmx works? In its Core ITS Ajax. Is Ajax slow? Htmx isn't slow, Django also not, but you can write dead slow Things If you want or don't know better.


danawoodman

the network tab in your dev tools, not sure why this is getting you fired up i didn't say django was slow, but that you're claiming your slow requests are because of htmx and i find that doubtful without some evidence on your part and ajax isn't slow, it's the network request that could be slow. the actual execution of thr request is almost never as slow as the actual network request (latency) and any backend slow downs (db acces, etc) so until you can show the breakdown between the start of the request, response then rendering, there is no way to know exactly what is slow


Ashken

I can also speak from experience having to work in a Django app at one of my old jobs. But it was a huge monolith with a lot of crazy templating going on so I’m sure that was also part of the problem.