Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace jinja2 with angularjs completely

What jinja2 can achieve, the same can be achieved with Angular.js. My question is- are there any advantages of replacing jinja2 with angular.js completely ?

like image 298
prathamesh Avatar asked Mar 21 '14 08:03

prathamesh


2 Answers

I think most problems came from the same obvious difference: Jinja2 is server-side, Angular is client-side, this makes they really different.

  1. SEO. Google don't understand Angular magics. It is just a heavy Javascript code and Google can't understand it fine. Sure, you have some workarounds to show your important text to Google, but to solve it you'll have to render some things server-side, going back to Jinja2 or some hack to render things to improve your SEO. (it is not important if you don't care about Google searches)

  2. Performance Server-side rendering is way faster than Javascript rendering. I'm talking about your average user, maybe with an outdated Internet Explorer and a crappy internet connection. With Angular, you have to wait at least some Javascript assets to be loaded before the page is usable. Users notice this and we know a slow site will hit your conversions. Check this Twitter article about "time for first tweet": https://blog.twitter.com/2012/improving-performance-on-twittercom

  3. Compatibility. Yes, they claim the framework supports all common browsers, but have full documentation about hacks to make it work for IE7. Depends of your audience.

  4. Maturity. Jinja2 is really stable, has a pretty API and is deployed with almost all Flask websites. Angular is still evolving and sometimes things just change a lot.

  5. Inexperience. You can't just replace Angular with Jinja2. When you try it, you will understand they are different and you must not work the same way with both. You will make a lot of mistakes before you make things right, just like with any new awesome tool you use.

Of course you can claim against all my arguments based on your specific needs, this is just some things you must understand before you go to Angular.

That said, I'm using Angular in several projects, mostly for single page apps. This is an awesome use case for Angular. In all these projects, I still use Jinja2 to some rendering, so this is not a complete replacement.

UPDATE:

Some updates almost two years after my initial response.

  1. Google is better understanding dynamic rendering, but I still don't trust it.

  2. I don't think the client-side rendering is a thing. Only realtime data is rendered client side, but the base HTML is generated server side.

  3. Angular dropped IE7/IE8 support. It is definitelly a good thing for the web, but unfortunately I still must support these browsers in some cases.

  4. Angular 2 is on the way, changing everything you know about current versions. I don't remember any major Jinja2 change.

like image 74
iurisilvio Avatar answered Sep 23 '22 00:09

iurisilvio


Why is replacement your objective? Use the power of both Jinja and other server side frameworks together with the power of client side frameworks.

The benefits of using both:

  • less and easy code
  • better performance
  • more easy to maintain
  • and much more. You have a choice.

Choosing for one or the other will make your work frustrating and complex.

like image 33
voscausa Avatar answered Sep 26 '22 00:09

voscausa