BigSmalls (5) [Avatar] Offline
#1
In this book we embed HTML in our JavaScript files. If we were to use Node with Jade to render HTML, would there be any implications we should be concerned about if still trying to create an SPA?

Thanks!
michael.mikowski (247) [Avatar] Offline
#2
BigSmalls wrote:In this book we embed HTML in our JavaScript files. If we were to use Node with Jade to render HTML, would there be any implications we should be concerned about if still trying to create an SPA?

Thanks!


Hi, thanks for your interest!

I assume you are talking about the Jade template engine?. I don't see why not. In fact, we recommend the Dust template engine in the book, and one of the reasons we focused on <strong>architecture</strong> not <strong>"framework" libraries</strong> in the book - you are free to swap out libraries as needed, while we focus the things you probably will need to glue them together smilie

My opinion about template libraries is probably pretty predictable: I do not recommend template libraries that rely on embedded JavaScript. Instead, I recommend you look for a library that has it's own DSL that is limited to display logic. And if it also supported embedded JS, but don't use it. Otherwise, it becomes far too easy to put critical business logic in a template, which makes it much harder to test and maintain.

Also, I do prefer explicit syntax (e.g. open and close tags or braces like JS) versus ruby, coffee-script, and python-style syntax, which, while "beautiful" is more difficult for machines and humans to decipher, and doesn't match the JS style. But that's a personal preference.


Cheers, Mike


BigSmalls (5) [Avatar] Offline
#3
Thanks, Mike!

I know what you mean. The company I work for uses Jade, and as you can imagine, a lot of the code is spaghetti because of it. I'm fairly new at working for this company so I don't want to be like, "All this code is messy and useless!" Rather than starting from scratch (tempting), I'm trying to recycle much of their jade code.

But it's put me in a funny place--the business logic definitely needs to go, but now I'm wondering about presentation logic: Would presentation logic be okay to have in a jade file? Such as, if user is logged in, show their avatar, else show generic profile picture. Is that harmful?

Also, on the server side, if you already have information which can be used to render the html, for example, a user's screen-name, wouldn't it make sense to go ahead and include that information in the render instead of having the client-side make another call back to a server to grab a user's information and then using JQuery to modify the DOM element?

Just want to pick your brain on this.

Thanks!

Sam