Back to the video

Modern JavaScript for Django Developers

Transcript

By Cory Zue. From DjangoCon US 2021. Published October 22, 2021.

Watch the video Markdown version 7,669 words · auto-generated · en

Summary

Cory Zue explains why Django developers may want to adopt modern JavaScript rather than scattering small snippets through templates. He compares low-JavaScript approaches such as HTMX with a fully separate React/Vue client and Django API, arguing that a hybrid architecture is often the best fit: keep Django templates, forms, authentication, URLs, and deployment, while adding React or Vue only to pages that need rich interaction. He shows that a JavaScript toolchain—typically npm, Babel, and Webpack—organizes dependencies, compiles modern syntax, bundles assets, and lets Django serve the result as ordinary static files, while still passing server-side data directly into the page. He also introduces modern JavaScript features such as modules, classes, arrow functions, template strings, JSX, Vue single-file components, and TypeScript.

Transcript

Automatically transcribed, so expect mistakes in names and technical terms. Filler words are removed.

0:00 Modern JavaScript for Django Developers

Hi there. So my name is Corey Zoo and today I want to talk to you about modern JavaScript. And yeah, your first thought might be JavaScript. Are you sure you're in the right place? Yes, I know this is DjangoCon. And yeah, I'm still here to talk about JavaScript. And to tell you why, like I first I first want to go back in time a little bit. And so this is me in 2017. I was feeling pretty good. I was feeling pretty relaxed. I had just gone on sabbatical from a job as a CTO of a relatively big team, maybe a 30-person team.

And yeah, I was feeling good. And I didn't really know what I was gonna do with my sabbatical. But I knew I wanted to build I wanted to build stuff and put it out into the world. And you know, I had been a Django developer. Our company had been building a big Django application for the better part of the decade. And so I knew I wanted to build stuff. I wanted to build stuff on my own and I wanted to do it in Django. And at this time in 2017, There was there was this new newish web framework that had just come out. People were really excited about it. It was called React. js, and I was like, cool.

So I'm gonna I'm gonna build some kind of side project. I'm gonna use Django, I'm gonna use React, it's gonna be great. Boom. And so I go to the React tutorial. And there's like a hello world thing and it looks it looks something like this. And like at first blush, this is very straightforward code to read. There's you know there's a couple of import statements. And then there is a function call that's that's rendering something that looks like a heading to a div with an ID or a document element with an ID root. And so like this makes this code makes perfect sense to me. And I'm you know I'm I can make I can reason with it and yet at the same time I'm like

wait a minute how do I use this code And at the time I had never seen imports in JavaScript like this. I didn't, you know, w where am I importing this from? Like I don't I need to include some sort of static file here to be able to call some function defined elsewhere. And then like you know this H1 thing like it's not it's not actually valid JavaScript. This is this is a special React syntax called JSX. But basically it was like oh I have No idea how to use this and how to do this in Django. And that kind of sent me off on a long a long journey. Learning about JavaScript, all that had happened in

the JavaScript world while I had been busy coding in Python. And over, you know, over some period of time I sort of figured a lot of this stuff out. And my goal with this talk is to sort of like bring you on that journey and hopefully sort of bring you along faster than I went along. So you can you can start using modern JavaScript in your Django projects without having to go through a lot of the sort of like figuring out process that I had to go through. So before getting into that, let's talk a little bit about sort of what was going on pre-2017 and in my life. And so Like I said, we were running a big Django application at my company.

4:19 The Traditional Django–JavaScript Workflow

And we were on what I would call like the default path to Django and JavaScript. It looks something like this first you build out your site using your normal Django stuff, your views, your templates, your forms. At some point you have to build something that has dynamic functionality on a page. Maybe you've got like a select drop-down and then the you know that controls the results of the next select drop-down, like a country state selector or something like that. And so you Google, you know, you go to Google, you type in like, oh, how do I do cascading select Django, maybe cascading select JavaScript? You find something on Stack Overflow that works, you throw it somewhere in your template file probably.

Maybe you add a library or two to make that work better. And then wash prints and repeat. And like this is so this is kind of how the JavaScript just gets brought into the Django project, sort of like page here, page there, functionality here, functionality there. We were doing a lot of jQuery at the time. These days maybe you're using something else. And like this feels great, right? Like this feels like it works. It's very simple. You know, you kind of introduce JavaScript when you need it. You know, we all recognize how this works and your pages are they're kind of self-contained, you got all your logic right there. So this is this is kind of like a nice it feels nice. It feels like a reasonable way to do JavaScript development.

5:51 The Limits of Ad Hoc Front-End Code

But what I would posit is that it doesn't really scale that well. And what I've had is like over time this just starts to get more and more unwieldy. Your front-end code, like it, it starts kind of getting spread around and scattered across all these different template files where the logic is used which makes it hard to sort of Track stuff down, it makes it harder to reuse bits of code, create functions, create you know libraries, that type of thing You're usually just sort of like at the whim of whatever you know static files you happen to include it at the in the base

template or somewhere in your template. And like you try to maybe you try to organize this stuff, but like You're not really like following any particular patterns. You might end up with this sort of like homegrown front-end organizational system that is likely replicating a lot of what there exists tooling to do for you today. And in general, it can become like a like a little bit of a complicated mess. So like I think this kind of leads to what I would call like front-end spaghetti code. Just like front-end code that's kind of like Sticking its tentacles in all these different places and a little bit hard to untangle from itself. And so in sort of like a Django JavaScript architecture tree, which is something I made up,

7:24 Choosing a JavaScript Architecture

I'll call this like the low JavaScript ad hoc architecture. And it's so it's low JavaScript because like by default you're you're you know gonna try to use Django for almost everything, only really bring in JavaScript when you need to. And it's ad hoc because you haven't really come up with any particular system or organizational plan to do this. You're just kind of throwing JavaScript at the wall whenever you need it. and hoping it all works out. And yeah, I don't really recommend this particular architecture. It can maybe work well for like a super small project, but you have better options out there. So what are those better options? And one of them is also a low JavaScript architecture.

But instead of instead of doing it in this like kind of ad hoc way, you do it more designed. Typically come up with like a low JavaScript framework and then you use that low JavaScript framework to do a lot of the stuff that you might normally be doing in an ad hoc way. So HTMX I think is what The Django community is most jazzed about these days in terms of a low JavaScript framework that will that will let you do some pretty some pretty cool stuff on your front end. There's also others, there's there's Hotwire which is a similar thing but kind of pioneered by the basecamp folks, so it's more popular in the Rails world. There's a Django specific thing called Unicorn, which has similar goals.

And these this is a good place to be for your JavaScript architecture. If you don't if you don't want to do write any JavaScript, then like these this type of solution with one of these tools doing most of your stuff on the server side can work really well. It's not the point of this talk. So I'm not really going to talk more about those options except to say that like they're perfectly good options Look into them if you don't want to use JavaScript. But what I want to talk about is the high JavaScript world. And so in the high JavaScript world, instead of sort of saying like I want to, you know like minimize the I want to write basically as little JavaScript as I possibly can. Instead you say, you know, JavaScript is

is a reasonable language. It is you know very popular on the web and I'm gonna embrace that, I'm gonna use it and I'm gonna kind of like go for it with JavaScript. And JavaScript will be sort of like a peer to Python in my code base world. So these types of projects are usually using like a one of the more popular JavaScript frameworks. So these days that's that's maybe React and View. Angular historically has been pretty popular in the Django world, although maybe going out of favor a little bit these days. Svelte is maybe the latest hotness. Actually I'm I I'm not like tapped into the JavaScript world enough to know what the latest hotness is. But Svelte was like the latest hotness maybe two years ago, which is why which is why I've heard of it. But anyway, so

so right, so Why be in this high JavaScript world? And yeah, so like how much how much JavaScript do you want to use in your project? And the way I think about that question, which I kind of already alluded to, is like Do you want JavaScript to be an afterthought or do you want it to be a core part of your code base? And so like if you it You know, if you are a person who really just like never wants to touch JavaScript, then yeah, like stay in a low JavaScript world. If you want it to be you know, a core part of your code base, if you want to have tests, if you want to have, you know, a good developer experience, if you want to If you want to be treating your front end the way that

most JavaScript developers would treat their front end, then maybe consider this high JavaScript world. And so like so yeah, so like the case for Lode. js, like basically like yeah, you don't want to write JavaScript. The one thing I'll add is like if you're a beginner, I would I would recommend staying in a low JavaScript world at least until you start to feel comfortable in Django. Learning web development is definitely enough of a thing to tackle to tackle at once. And so learning the Django side of the house and the JavaScript side of the house at the same time, I think, is a lot to bite off. But yeah, so on the high JavaScript side, like obviously if you like JavaScript already, that's

that's a good reason to use it. If you have a very complicated front end, I think you'll You'll be happy that you kind of went for high JavaScript and if your project is big I think you'll want it. And like I don't want to say that JavaScript is inevitable. Instagram on you know Django and HTMX and never has to write a line of JavaScript. That would that would be amazing. I would love that. It feels pretty inevitable today. to me at least. And like just based on sort of that, you know the way like where people's expectations are for the usability of a front

end in anything sort of like remotely complex I think you're gonna be in a world where you're you're gonna be writing some JavaScript. And if you know that you're gonna be writing some JavaScript, then like Better to be in this high JavaScript world where your JavaScript development experience is pleasant and you have access to sort of like the latest and greatest tooling than to have it be this sort of like neglected thing off to the side that you then have to, you know fight through, essentially. So I kind of think JavaScript is inevitable, and that's why you might as well go for sort of like a high JavaScript world from the get-go. And yeah, like living in a high drive script world, it's it's nice. You like I said, like the developer

experience is really good. You know there are like if on the Stack Overflow surveys like JavaScript developers are like the happiest developers. JavaScript is really good. And the problem is that like getting to a high JavaScript world can be painful. And it's painful because it's complicated, although it's not as complicated as it sounds. It's also painful just because like I think the community doesn't do a good job of opening itself up to like non-JavaScript developers. And so a lot of the projects that you'll try to use on the Java with JavaScript on the front end, like they also assume that you're kind of like probably going to use JavaScript on the back end. And obviously us as Django developers are likely not going to be doing that.

14:17 The Client–Server Architecture

So getting to this high JavaScript world is can be a bit of a mission. And that's really what I want to spend the rest of this talk kind of like talking you through. And so what is what does Hi JavaScript look like? And your first take will probably look something like this, which you can call like the client-server architecture. And basically in this world you have your JavaScript projects and your Django project. They're basically two completely standalone projects that that just speak to each other over API. So you have Your front end on one side, it's you know it's using a framework, it's it's probably a single-page app and it's it's probably just sort of like a pure JavaScript thing

You have Django on the other side. It is headless mostly, so you're not really using like Django templates or views or anything like that. Instead you're using Django Rust Framework. to basically be an API into your database and your authentication system and stuff like that. So this if you just Google like, you know, using React and Django, this is this is the architecture that you're most likely to sort of Find people recommending and telling you that this is how you should do it. And this architecture works well for certain projects and for certain teams. It allows you to go all in with a JavaScript framework. And so like if you're already a React develop React developer and you want to write your entire UI in React and you know that from day one, that that makes sense.

Similarly, if you're a team and half your team knows React really well and the other half of your team knows Django REST framework really well, then you get this nice sort of like clean like okay here's the front end world and here's the back end world and you front end people you never have to think about a database like you just you know we'll we'll give you like a server somewhere that you can like test your APIs. You back end people you never have to like know how to change the color of a text box or something like that. And so like this architecture can work well. I think it works well that maybe the bigger your team is. But like I want to just kind of talk about what it looks like to build a forum in this world. And so like first, you're gonna need some APIs, so you're gonna create your you know

your create, read, update, delete APIs for your for your data model Then you're gonna have to build some JavaScript UI components in your framework of choice. You're gonna have to write a bunch of glue code. That glue code is gonna hit you know your list view API, it'll you know render your list of objects and then you know wire your inputs to the you know you know, associated JavaScript data model and then when you press save it's gonna hit your update API. So you're gonna write a bunch of that stuff You're gonna have to authenticate. And so you'll probably be doing some sort of like token-based authentication thing, JWT something.

Cores, you might have to deal with cores, cross-origin issues as a result of your front end and your back end maybe running on different subdomains or in different processes. Your front end might have to handle URL routing because if you're building a single-page app, then you're probably doing URL routing on the front end. And etc. And so like this thing that Django does, you know, in you know 30 seconds I can spin up a form and basically have like a complete like you know create reit update thing working like it's just it's it's a lot more work in this architecture. Sure. And that made me sad. And so I don't I don't particularly love this architecture either

Looking at like the intro to Django and like this is like from the Django docs, like here's all the great stuff that Django brings to the table. And this architecture like kind of throws a lot of that stuff out the window. Like it's It's not using the URL and view system really. It's not really it's not using templates, it's not using forms. And it kind of half uses like a lot of things like authentication and internationalization. Like you have access to those features, but you're You're wrapping them, you're you're probably using extending them with a library or something like that. And so Yeah, like I think one of the reasons why I love Django, why a lot of us love Django is that like it does so much for you. It sort of like comes with like

a lot of batteries included and like you know a lot of stuff working out of the box. And if you use this architecture, it's kind of like, yeah, maybe like maybe bring your own batteries. Like we don't those nice Django batteries, those are good batteries, but like I don't like those batteries, so like come bring your own batteries. And so for this one I chose an Energizer Bunny mascot because he's he's gotta like carry his own batteries around and bring them everywhere he goes so right, so this wasn't great for me either. And so what's left? And thankfully there's there's one other option, and that option is what I would call like a high JavaScript hybrid approach.

19:38 The High-JavaScript Hybrid Approach

And for me this was this was like the unicorn that I had been searching for. Once I had found my way here, I was like, of course, like this is the way. That I want to be building be building my complex Django projects. So what does a hybrid architecture look like? And basically instead of instead of like choosing like locking ourselves into like client server you know, for our whole application. We pick it at the page level. And so some pages, probably most of our pages will be will be Totally vanilla Django. If you're building a setting screen for user preferences or something like that, there's no need for that to be this like complicated, interactive, single page, blah.

You can just You can just drop in a Django form and not have to worry about it. But when you wanna sort of build a rich UI, then you drop into modern JavaScript and then you have access to all the tooling and libraries and good stuff that modern JavaScript can bring you. And like this sounds super obvious once you piece it together, but if you if you haven't sort of wrap your head around the JavaScript world. The key insight is like at the end of the day, like JavaScript is still just another static file. And so You can still use React and Vue and these other things just like you would use

21:13 Why Hybrid Apps Need a Toolchain

drop in a jQuery from a CDN or something like that. It's it's just another static JavaScript file that gets landed on your page and renders your thing. But wait a minute, so what about this? Right? So how do these how are these imports gonna work? How what is this, you know, how are we gonna do this H1JSX thing? And the answer is that is that you need a toolchain. And I will say like The idea of needing a toolchain, it was it was very, very true, you know, five years ago. It's it's becoming less and less true every day. Browser support for a lot of modern JavaScript stuff, including imports,

not really including JSX yet, is getting a lot better. And so you Like you can actually get pretty far with modern JavaScript without a toolchain. But toolchains are nice and they're relatively easy set it up. And so I recommend them anyway. even though technically maybe you could you could get away without them and some people some people may choose to And so what's what's the point of tool chains? And so like I said, sort of like they were they were much more important you know maybe five years ago. But basically it's like Python, we have the luxury of mostly controlling what Python environment our apps are going to run on.

I know that's not always true, but for web it's it's pretty true. You can control what version of Python you're putting on a server. In the JavaScript world on the front end you don't have that luxury. Your front end ideally it runs on some you know ancient Nokia candy bar phone or something. It should run you know on iPhones and Android and Linux and Windows and all that. And so the JavaScript world has like it's kind of been locked into this like perpetual backwards compatibility problem where because JavaScript needs to run on all these old browsers and everything else, it was hard for the language to innovate. And that's that's where toolchains came in.

And so Toolchains basically allow the JavaScript world to keep iterating, allowed the language to keep getting better. And then you funnel this new JavaScript through a toolchain and you end up with something that still works in all browsers. And so yeah, like if you still think that like you know JavaScript is like this clunky language with no features and whatever else, then like you're probably not using a toolchain and you probably haven't been paying enough attention to advancements that have been happening in the JavaScript world. And so like JavaScript, like yeah, like now it has modules, so you can import, you know. JavaScript stuff from you know from libraries that that you install.

You can import it from other files that that live on your system. So you can you can organize your JavaScript code however you want to organize your JavaScript code, just like Python But this isn't always obvious to someone who's only done JavaScript development in the browser It also has, you know, like new syntaxes have been added to the language or extend the language and allow you to have sort of like a richer experience building UIs. So okay, so we're gonna use a toolchain. What toolchain should we use? And this like this is where I got really frustrated with the JavaScript world because A, there's like a hundred different options, and then B,

the JavaScript world is like really unapologetic about like teaching you how to use this stuff. It's it's they make I found they make a lot of assumptions about like the things that you would know and I found it very overwhelming trying to figure this out when I was when I was first getting into it. But anyway, so the React Docs, they recommended like if you're integrating with an existing code base, to try out this like more flexible tool chains area. And so you go over there and then like so again, there's like there's like a ton of options. And like when I was reading this, like

Neutrino combines the power of Webpack with the simplicity of presets. Katrina combines the power of rubber. Like my first thought is like, what is a webpack? What is a preset? How like You know, what is like how would I even think about cho like is this list supposed to be helpful? Like this is supposed to help me choose something? Like I can't even I I'm gonna have to like open up a new tab for every one of these words. And so I found this very frustrating. Again, it made me feel kind of kind of dumb. But I promise like it's it's not as hard as it seems. These tool chains are relatively Simple, there's a few tools, they work together. So right, so what's in the toolchain?

26:34 Package Managers, Compilers, and Bundlers

And it's three things. The first thing is a package manager. And the package manager is just its pip. That's really all you need to know about it. You're gonna run you know, package manager install blah. It's gonna have a file that tells you all the libraries that you've added to your project and what version they're on. It'll manage your dependencies and stuff. The main options these days are NPM and Yarn, and it doesn't really matter which one you can pick, but NPM is a little bit more popular. So I recommend that. And I'll say like these like tool recommendations, like there's it's just like pick the most popular boring thing and move on is my philosophy. I'm not trying to be like the on the bleeding edge of wherever the like the JavaScript tooling is going. And so that's that's how I made these recommendations.

If you talk to a JavaScript person, maybe they'd say something else but these will all be perfectly fine for a Django project. So the second piece of the toolchain is the compiler or the transpiler. And It's this thing that that allows you to sort of like write new JavaScript or different JavaScripts. And it will take modern, you know, like these newer syntaxes and features and turn them into turn them into code that runs on a browser. So Babel 's the most popular one and you can see like it'll you know it'll parse this JSX thing, this H1, and turn it into just like a normal function call behind the scenes so that you don't have to write you know this code that looks kind of

less nice than this code on the left. So Babel is a good compiler. And then the last piece is the bundler. And the bundler, the bundler does A few things. It's it kind of carries a lot of weight. But the main thing it does is it makes bundles. Bundles are just a single file with a bunch of bundled code into it. And so the way your bundler works is you'll you'll tell it sort of like, here's my entry point. So like maybe this is like my React, you know, my React home or whatever. And then your bundler will see everything that you've imported in that file. It'll go pull that code in, find the dependencies of that code, build a tree.

You know, compress it all together, turn it into a single file and then that file will be like a self-contained thing with the exact code necessary for that entry point to run. Bundlers also kind of have hooks that you can add in sort of pre and post-processing steps. So your compiler will kind of get integrated with your bundler usually. And you know they can do things like you can add you know CSS processing and other stuff. But anyway, there's a lot of there's a lot of options out there but Webpack is the by far the most popular one. And a lot of like if you know if i the all those different tool chains, you know, Nix and Neutrino and Razzle and Dazzle and what and whatever they are.

Like a lot of them are using these tools behind the scenes and they exist to sort of like remove this complexity from you, like to like so that you don't have to ever know that they exist and you don't have to you know ever edit a webpack config file or whatever. The problem is they're mostly designed for the JavaScript ecosystem and so they like they just don't like plug that cleanly into Django, which is which is why I prefer to just work with the primitives. And the primitives are relatively straightforward. The config files are not that You know, complicated or anything else. So yeah. So that's your pipeline. So just to review, we've got NPM which will control

our all our third party libraries and packages and stuff. We're gonna use it to install our dependencies. Babbel is going to allow us to write code in the latest JavaScript features how we want. We can use JSX and TypeScript and these other fancy things. And then Webpack will bundle it all together and create you know one or more bundle files that we can just drop into our into our pages and they will work beautifully in browsers. And so finally coming back to Django and this insight that that at the end of the day your you know your fancy modern JavaScript, whatever is just another file, now we know it's a bundle file.

31:16 Integrating Bundles with Django Static Files

You can just shove this whole thing in front of in front of your Django static files And so you can have your JavaScript source code in this modern thing running through this toolchain and it'll spit out bundle files, which you can then just drop into your static file system however you want. And then you have Django serving a React app for you. And it is just that simple. So what does that look like in practice? And so here's here's like how I structure my projects. So you know you've got your manage. py and your site directory with your settings and stuff your root URL confit, then you've got you know some apps with your models and stuff, and then

basically you just have another folder somewhere. You I call it assets, you can call it whatever you want. And in that folder, you'll have your modern JavaScript code, your React pages, whatever you want to stick in there. And then that stuff gets run through your toolchain and spat out into your static directory. And yeah, I think you know in development you can just build that into your system. Usually you'll have your built into your CI or your deploy process will run the same thing and Django will just serve those static files just like any other static file. And so here's what a single-page React app looks like

in a Django template. And so on the left is that same code snippet that we've seen everywhere. That gets run through the pipeline. and stuck into a script that is just included just like any other script in as a static file. And then the only other piece that links these two is this div with the ID root which is declared in the Django template and React will then find that div in the Django template and render itself into that div And so on my website, the link is down there, and I'll there'll be another link at the end of the talk. But I go into much more depth about

how you can do this, all the config and everything else, and then also kind of like all the API side of things and working with data and all that. So if you're interested in how to set up a Django and a React hybrid application together, I recommend you go check out that page and find details there. And right, so why bother with this? So why hybrid? Why is hybrid better that why do I like hybrid better than this like client server thing? And the first the first one is just like we don't throw away the batteries anymore, which is great. Like because we're mostly just using Django as is because React is totally optional on any given page. We're still using everything.

34:21 Benefits of the Hybrid Architecture

We're still using the URL system, we're still using templates and forms. authentication and all that good stuff. And so we can just use Django how it was meant to be used, which is great. It also vastly simplifies deployment. And again, like now, you're not deploying a React app running on Node over here and a Django REST framework over here and then messing with cores and it and whatever else. You're just deploying a Django app, and that Django app is hosting a static, you know, a static file. So your deployment is exactly the same as if you were deploying a Django project of no JavaScript and you can treat it the exact same way. Which is great. You can also

so another nice thing about this is that you can you can work with data without having to create APIs. And so in the client server world like If you had an API, if you had in this example, let's say we have an employee data model and we want to we have a department field on the employee data model and the department should be one of these. these choices. If you wanted to build a React app that allowed you to set an employee's department, There isn't like an obvious way to pass this information to React. You could create an API for it and then like You'd have to hit this API just to just to populate a drop down, which seems kind of crazy. Maybe there's some sort of like schema introspection thing you can do with Django

Rest framework but that's That's kind of territory that I don't always like going into. Or you can just duplicate this list of code these list of choices in JavaScript. But then you know if you add a new department then you're gonna have to remember to keep those in sync. But in a hybrid world, you don't need to worry about any of that. Because your React code is running in a Django template, you can actually just like pass some context to that Django template. And so in this case, I'm just serializing the department choices into a dictionary. and passing them to the template. And then you can use Django's JSON script tag to serialize those choices into like a div

element essentially and pull them out in JavaScript just by grabbing the element and the contents. and parsing it in JSON. And so this will allow you to get access to these employee department choices anywhere in your React code. They're being served directly from Django. You don't need an API or anything like that. It's just as easy as passing context to review and a few a few helper function calls. So this is a nice little benefit of hybrid apps that I like over the client server approach. And like most importantly, like You get the modern front-end development experience. So you'll be able to use the latest JavaScript frameworks like React and Vue. If you've never used them before, they you know they've got a bit of a learning curve, but

Building UIs in them is very enjoyable once you get over the hump. They also there's just like such huge amounts of a front-end tooling around these things now. Like if like you can you can build a very complicated UI with like you know video uploads and like super complicated navigation. There's like all these React libraries and view libraries that will just like do this stuff out of the box for you. So you get to sort of stand on the backs of all of the work and advancement that has done on been done on the front end over the past five plus years, which is really nice not having to re-implement a lot of that stuff. I mentioned you get better dependency management.

So you know that'll all be sort of like natively baked into your JavaScript code and handled by Webpack. You don't have to worry about. including the right libraries and static files and whatever else in your base templates. And then you just get like a better JavaScript development experience. You get you know new features and syntaxes, you get Things like TypeScript if you want, other front-end tooling, you're like so the same in the same way that JavaScript has innovated a ton over the last you know 10 plus years. CSS has also gone through tremendous innovation, but because of this backwards compatibility issue, it's again it's you can't bring all that innovation without a toolchain. But if you have a toolchain set up, then you can use things like SAS or Post

39:02 Modern JavaScript Language Features

CSS and apply sort of like a similar upgrade to your to your CSS development experience. which I recommend. And so yeah, so like what is What is in modern JavaScript? And honestly ES6 is ES6 was a big update to Java that it's probably like six or seven years old at this point. So it's it's Barely even modern anymore. But if you if you haven't used it, it has a bunch of stuff. The I think the most important one is modules. So I've talked about this a lot already, but Just being able to structure your code however you want, define, you know, break it up into files and folders and whatever else and then be able to sort of import and export stuff.

And just have a front-end code base that's organized is a nice change of pace from how things used to be. ES6 also includes classes which work just like just like Python classes basically. So no more do you have to sort of like invent your own JavaScript class system They have arrow functions which are just like lambdas essentially, but allow you to do shorthand for inline function declarations and you find yourselves doing that a lot in using frameworks like React because you write these little event handler things. And they're really useful for that. They have template strings, which work just like F strings.

They have default argument values. And like In general, like you know like programming languages like the same things are useful in all programming languages. And so just how Python has gotten better and better and better, JavaScript has gotten better and better too. And like these days, JavaScript is it's it's It's probably got like everything that you would want in a programming language. And be in be set up to use it. This is JSX. And JSX it's it's a lot like a Django template, honestly. But instead of having like its own template language,

you can kind of just drop into JavaScript anywhere. So you can write your UI in something that looks a lot like HTML but isn't quite HTML, it's actually like a little bit more XML-y. And then inside that HTML you can you know put in some brackets and drop into arbitrary JavaScript code. And so this allows you to Again, sort of like mix and match your UI with your business logic in ways that allow building a UI to be like a much more pleasant experience. Quite similar to Django templates. But button JavaScript. View does something similar, you can see here with this template thing. Vue also has these sort of like these single files that that have a template section, a script section, which is where the business logic will live, and then a style section.

And the styles can be scoped to this thing, so you don't have to worry about like your you know one particular component style like bleeding out and you know affecting other stuff on the page. So that's nice. This allows you to create these sort of like self-contained reusable components that you can then combine as little like building blocks to build UIs. There's also TypeScript. TypeScript is again, it's very similar to Python 3's typo annotations. But it allows you to declare, you know, types for classes, for function calls, and if you've set it up, then you'll get nice IDE support for this, auto-completion,

you know, red squiggles when you do something wrong, all that good stuff. And so yeah, just like Python type annotations, it's it's a really useful upgrade to development experience when you're when you're working with it. And lots more, yeah. So you know I I've I've just scratched the tip of the iceberg in terms of JavaScript, both in this talk and in my own career. I still feel like I'm I'm you know barely swimming in terms of what you can learn. But I will say like it's worth it. It's Like being in a position to do JavaScript development the way it was meant to be done, the way that you know JavaScript developers are doing it these days is really nice

and I would say it's worth the investment. So yeah, so that's that's it. Thank you. Thank you for your time. And I mentioned, yeah, this whole talk is based on a series of guides that I wrote up. So if you want to see any of this stuff in like much, much, much, much more detail. You can go to saspegasis. com and then click guides and you'll find very extensive write-ups there And that's me on Twitter and on the web. Thank you.