Wagtail architecture options, or should I go headless - Dan Braghis
Transcript
By Speaker 1, Speaker 2, Speaker 3. From Wagtail Space NL 2022. Published June 30, 2022.
Watch the video Markdown version 2,758 words · auto-generated · en
Summary
Dan BraghiÈ™ compares three broad Wagtail delivery architectures: server-side rendering (SSR), single-page or modern JavaScript frameworks, and static site generation (SSG). SSR is the simplest, most established choice and supports forms, personalisation, A/B testing, search, and other dynamic features; SPAs offer richer interactions and a wider JavaScript ecosystem but add development, deployment, and hosting complexity; SSG produces fast, cheap-to-host, secure HTML but becomes harder when sites need dynamic features or must rebuild tens of thousands of pages. He recommends starting with SSR while enabling APIs for future expansion, choosing SSG when its constraints fit, and evaluating SEO, previews, build times, team skills, and the specific needs of the site rather than adopting headless architecture by default. He also explains that hybrid approaches are possible, combining static content with server-rendered or externally powered dynamic features, and points viewers to Are We Headless Yet? for Wagtail headless support.
Transcript
Automatically transcribed, so expect mistakes in names and technical terms. Filler words are removed.
0:02 Introduction and Architecture Options
Speaker 1
All right, hi everyone. My name is Dan and I work for Torchbox and I want to talk to you about wagtail architecture options. So this talk will be less technical than you'd expect and it's kind of geared more towards decision makers in companies, but also hopefully you know there will be little bits of little information nuggets that you can take away. I try. I guess we'll have to go with this. Let's see. Okay. So who am I? I'm a technical architect at TorchBox.
What does that mean? That means I help lead on projects on big projects and also you know, make the tough decisions on architecture, but also enable people sometimes a lot smarter than me to do their job properly. I'm also a Wagtail core developer and I've been involved with Wagtail for from quite early on. I started by taking meeting notes and Publishing blog posts. So some of the earliest blog posts on wagdale. org are essentially meeting notes from me. And I must have been doing something right because I got accepted. in the in the in the core meeting. And also I I'm a maintainer for a number of packages like Wagtail Media, Wagtail Headless Preview, Wagtail Grapple,
and a handful of others. So yeah, so what it is this talk about? There we go. So this talk is about lots of acronyms, acronyms like SSR, SSG, SPA, ISR. and so on and hopefully less bad animations on slides. So yeah so let's take it one by one yeah know SSR what is a SSR that is when we talk so I try to distill architecture options into like three main categories. There are more that sit in between,
2:23 Server-Side Rendering
Speaker 1
but I won't focus on these. So SSR, server-side rendering, and this is you know the good old boring technology that we all know and it really it's the simplest model everyone does it it's battle tested it works right and what's really good about it handles every kind of use case because it has had so much so much run. Now next up we have spas, right? Single page applications. Now when I talk about SPAs, I kind of include
3:08 Single-Page Applications
Speaker 1
All of all of the modern frameworks like NUX Next. js, Gatsby, and so on. And it's a bit of a stretch because they're kind of evolved from the that concept of a you know single page application where everything is happens into this one little page. But you know doing star page applications or dynamic page applications doesn't quite have that ring to it. So I'm I'm gonna refer to SP to that kind of frameworks or approach. as SPAs. So like what is behind it? Well you have a back end in this case well Wagtail that provides an API
and then you have a front end that consumes that API and renders your components, it renders full pages and provides interaction for your side. So where are single applications good? Well you know you can tap into a wider developer community So there all the JavaScript led stuff is quite hot, you know, right now. Everyone does it. Everyone like likes it. So you can increase the pool of developers can that can do it. There's also like a quite rich ecosystem behind it which helps. So you can have nice slick
interfaces and you can have smooth transitions, faster page reloads, also more dynamic applications. or websites. And it also taps into this concept of cope or create once publish everywhere. And the idea that you have a single source of truth that is your backend that provides the API and then everything else can be you know your website your application your publishing feed whatever it is. And that works quite well for big publishers. Now to continue on this, you know, I talked about modern frameworks like nuxt and next and so on
so these applications can be rendered on the client side meaning everything all the logic Happens on the client side, you load JavaScript and that takes care of things on the page. And that can, you know, that has its pluses and minuses That can sometimes be faster, but also it come it can come with an overhead depending on the type of the application that you have. Those applications can also render things on the on the server on the server side so you saw with the previous next js talk, a diagram that kind of talked about that a bit.
some come with this kind of universal or hybrid rendering, which means that But they will render pages dynamically and then cache them and kind of make them static. So that kind of incremental approach. And some of them, or quite a few of them, will also do static generate generated. So what what's static generation, right? So static site generation takes that concept of essentially it you it take your data and you generate a static site meaning good old plain HTML files that don't change and creating chaos. Yeah, so
6:51 Static Site Generation
Speaker 1
and you generate your site, y it's essentially just that HTML and CSS and then you can deploy anywhere and it has like unbeatable performance because you don't have to re-render things. It's really easy to cache and as it says there, you know it's quite cheap to host. And frankly, in my view, that that would that's the holy grail of websites. Kind of it's we started with static websites and kind of with sort of making that circle again. Now so kind of trying to visualize the different types of these applications. So, you know,
server-side rendering, you have your audience, your client, that essentially talks to your backend and your backend generates the resulting files and serves them back. With SPAs or the you know the modern frameworks you have your back end you have the front end that then the audience talks to mostly to the front end but from time to time it will happen that they have to talk about to the back end and then do that whole round trip. And then with SSG essentially you have the you know you have your back end that generates the static content and then your audience will always hit that
That that static content. Now one of the things kind of decision makers have to take in consideration is you know is development costs. So if we take server-side rendering as the baseline, you know what are the costs of the other options so and this is like highly unscientific because there are many factors that that that will influence that but generally if we if we take the traditional approach at 1x if you try to if you do the static side generation j that incurs slight a slight additional development cost be it adding additional module for example loctel bakery
8:43 Rendering Models and Costs
Speaker 1
or you know whatever your tool of like next jazz or knox jazz has the capability right and then if you look at spas then the cost can increase and that there are a variety of factors you know how familiar you're team is with the product, you know, whether it gives you all the capabilities or not. Then there come the hosting costs, right? So if we take SSR as the or server side rendered as the baseline, then hosting statically generated sites it's like really cheap. Really cheap. And then SPAs, the cost is higher because you have your back end
10:02 Tradeoffs of Static Sites and SPAs
Speaker 1
which you have to host somewhere, but you also have the front end. Now, what are the disadvantages of static site generation? Well, if you want to have dynamic functionality, dynamic content. such as I don't know search, pagination, and you have to do additional tricks to kind of account for that. Also if you have a large website then kind of you can have page build delays. And if you you're also trying to paginate, that kind of exponentially increases the number of pages that it has to generate. So it's a trade-off that you kind of want to consider. So if it's a few hundred pages, sure that's that's gonna be fast. But if you have tens of thousands
, editors may not want to wait, you know, five, ten, fifty Minutes, whatever it takes. So, what are the disadvantages for single page applications? Well, there is an additional development complexity because all of a sudden you have different tool chains and different methodologies and different technologies to kind of account for. And also you kind of have an additional layer in terms of like the deployment. You have there are different kind of ways of doing of deploying your backend and the front end. So here are some like rules of thumb right so
11:32 Architecture Selection Guidelines
Speaker 1
If you want like if the your main like driver is security go for it statically generated sites because at the end of the day what the public ever sees is a bunch of HTML files they cannot do anything with it Now if you know you want like a Dasnaziest the most modern experience, the smoothest experience and a lot of dynamic stuff, you probably SPAs are the thing to go. And then well for everything else, forms, A-B testing, personalization and
handful full of others right go with the good old trusted technology so server side rendering yeah so again if you want to and also if you want to optimize for developers speed you know go with server-side rendering because that's good old trusted stuff user experience and also just fancy nice new stuff SPA and then security SSG. Right. Now I don't have time to go in all of the considerations because you have to think of you know SEO does your framework or does your technology allow you to do a good SEO search you know
13:05 Headless Wagtail Recommendations
Speaker 1
Dynamic elements and also previews. Like, does it solve previews easily or do you have to jump through a lot of hoops? Anyway, the main question probably a lot of people are asking nowadays is like, well, should I go headless? And it depends really. And you know, our recommendation is to start with server-side rendering because that's just works. But while you do that, you want to like enable the APIs and kind of build something with the with the APIs with the with a view to potentially expand to you know more dynamic single page applications. Now and really SSG is that holy grail and if you can and if it matches what you need then go for SSG.
13:52 Are We Headless Yet?
Speaker 1
But your mileage may vary and you should kind of look at this and see how that fits into your context you know your experience with the different technologies the resources that you have and you know the what the developers can and want to do. Oh yeah, one more thing. So you've heard it mentioned earlier, but we Like our team put together a thing which is called Are We Headless Yes? Are We Headless Yet? And it's a status side that kind of keeps track of whether Wartel is headless ready or not. And that's available at are weheadlessyet. wattel.
org. Please go. There are a few areas we'll keep up Updating that, post links to relevant issues, blog posts, news, and so on. That's all. Thank you very much. Thank you. There's a question.
14:59 Questions
Speaker 2
So we've got a question from online from Kjaten. Would it be we would it be realistic to consider static site generation strategy for a site was 150 KU plus unique pages where dozens of unique pages are created every day. A news large news site for example.
Speaker 1
Again, it depends. What's the build time for that? What other capabilities you are you adding? to your site. If it's just like a an archive of things, sure thing. If you want dynamic pagination and yeah, more than a search, you have to put the you know the work into making that happen. And sometimes that's not realistic. But the options are there. There's you know Django Bakery and that that will or Wagtail Bakery which is built on Django Bakery that will allow you to do this. I know that Mozilla used to run in a statically generated a website for I think
MDN, so Mozilla developer network. But they eventually switched to good old server-side rendering because of paginational search. So again, it can work, but it depends on how much you want to invest in it.
Speaker 3
Yeah, I'm just wondering if you ever thought or would advise on combining the options. For example generating static pages for not much visit like archive pages. And using service vendoring for well the difficult stuff like search pagination, almost every site would want that, I think.
Speaker 1
With JPL and their they have the main JPL website is a headless website and it's built with Nux JS. And some of the dynamic areas there, I kind of use a hybrid approach where we kind of piggyback on elastic search for example. to build to kind of to have that hybrid approach where with more statically generated content and more dynamic areas of the website. So it's it's one of the many possibilities. I kind of tried to try to distill these in like three main, but there's everything in between. And People do that.
People will do that. And there are ways. And sometimes we even with like with Next. js you saw there's incremental static rendering. Which kind of does that. So there are ways to go around it. Any further questions?
Speaker 2
static site generation in the first place. So they ask how should I make my blog static such that the user never hits the database backend but only accesses the static content
Speaker 1
Well I mean again my answer will be it depends. But yeah Try you know you can try Wagtail Bakery, for example, and that will bake your Wagtail site into a like a static one. And then you can put in some, there's like little Lunar. js or other services that could allow you to search for things. Did I get that right? Yeah. I think in a lot of cases, right. you also won't have a degree of experimentation on play because you can you cannot make a choice unless you've tried several of the options
and you kind of know what's involved in them. And I wouldn't kind of s recommend to peop to people to kind of go, yeah, go jump and do headless or I don't know even server-side rendered you know with wagtail if your strengths right are in a different area so try to play to the strengths to your strengths to your capabilities