3 ms·
An alternative that requires even less server-side work is to use PJAX https://www.npmjs.com/package/pjax https://www.npmjs.com/package/pjax which is the spirit
by btown 5y ago
An alternative that requires even less server-side work is to use PJAX https://www.npmjs.com/package/pjax https://www.npmjs.com/package/pjax which is the spiritual successor to Turbolinks from the early Rails days. It's really a two-step process:
- create a quick JS file that loads and configures PJAX to automatically intercept links and
- wherever you would have $(function() {}) ensure that it's also triggered on the PJAX load event, and is idempotent (e.g. check if you initialized a component before initializing it again)
Then you just render pages server-side like it's 2000, without any pjax-specific code needed in your templates themselves.
If you're building a data-focused product either solo or with a small team, it allows you to focus on your Python code, and anything frontend is as easy as accessing the variable in a Django template. Of course, it's a massive accumulation of technical debt - when you're successful you'll need to rewrite in a modern framework for maintainability and agility. But when you need to "punch above your weight class" and just get a product out into the world, it can be an amazing technique.
- hermes8329 5y agoSince when is Django not a modern framework?
- acdha 5y agoI read that as a modern JavaScript framework. I think there's definitely a good debate about what “modern” means in that case because I think it's less about “modern” and more along the lines of “suitable for a large team working on complex client-side functionality”. Reaching for that prematurely can add a massive toolchain to your critical path, which adds a lot of frictional cost you might not see sufficient benefit from. One of the challenges we have is that people tend to hear about practices from very large tech companies because they have enough people to have things like developer evangelists and time to write lengthy blog series or produce videos. That often leaves people without the nuance that some of the tradeoffs make more sense when you have 50 developers including a dedicated support group but smaller teams might not make back the cost of entry. I like posts like this for reminding people that there are other options which might be appropriate for different projects, especially since even at large organizations it's usually easy to find small projects.
- hermes8329 5y agoI figured they meant js frameworks. This is definitely my slanted point of view but I rarely consider anything JavaScript modern. Django 4 seems much more so
- recursivedoubts 5y agopjax (first released 8 years ago) preceeded turbolinks (6 years old), and was the inspiration for it htmx is an attempt to drive HTML forward as a hypermedia, so it exposes explicit, client-side attributes, rather than hiding them as with pjax/turbolinks, although there is an attribute, hx-boost, that acts similar to them both worth noting that intercooler.js, which was the predecessor for htmx, is 8 years old as well
- btown 5y agoI stand corrected on the timeline!