Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Richard Hriech](https://secure.gravatar.com/avatar/b658d9a8e06adb34676060e11effba02?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Richard Hriech
12,001 PointsWhat should I use? Jinja's {% extend ... %} or an AJAX request?
So if I'm building a Flask web app, where the site has a static navbar, sidebar and a main page content that changes when the user clicks on a link, which is the way to go?
- Making a "layout.html" with a {% block content %} and the subpages of the site extend this layout and change the content,
or
- Not using Jinja's templating, but requesting a html snippet from the server with an AJAX get request, and only changing the <div> of the main content while the navbar and other static stuff remain untouched and don't get refreshed.
Is the AJAX way faster or more data usage friendly? Or the browsers are clever enough to cache the navbar, css, and scripts and they don't reload them every time I go to a subpage?
1 Answer
![Jeff Muday](https://uploads.teamtreehouse.com/production/profile-photos/5900142/micro_jeff_face.jpg)
Jeff Muday
Treehouse Moderator 28,718 PointsPersonally, I'd go with the Jinja approach. Since we are already doing the majority of the work on the server-side, why not extend a base-layout. Of course, I am weak at Javascript ;-)
Pros:
- If you want to change the layout, you only have to do it in 1 file (admittedly, well-crafted AJAX is nice and modular too!)
- If you have a client that doesn't support javascript, Jinja will produce the static pages.
That being said... there is a new trend of doing "serverless" pages-- but that discussion is better left for another day!
Cheers