开发者

Should I be rendering html on the server-side or client-side?

开发者 https://www.devze.com 2023-04-12 23:31 出处:网络
I am looking into Backbone JS and getting a little confused. I am used to compiling my page html on the 开发者_如何学Goserver-side (using JADE) and then interacting with these elements using jQuery on

I am looking into Backbone JS and getting a little confused. I am used to compiling my page html on the 开发者_如何学Goserver-side (using JADE) and then interacting with these elements using jQuery on the client-side. A lot of the backbone examples suggest starting from a blank html body and rendering content on the client-side.

This seems really strange to me!

Questions:

  1. Do I have to use client-side templating?

  2. Can I use BackboneJS to control pre-written server-side compiled html?


The typical way of using Backbone is to do things client-side. You use client-side template rendering to bind model values to your small view templates. It is an approach to turning HTML/JS into a application development platform with an actual component model.

BUT, that doesn't mean that you can't or shouldn't mix your worlds.

For example, I use Backbone with Rails. My Rails view renders server-side HTML which includes Backbone logic/views. Then, all of my AJAX-style view rendering happens using Backbone with models, views and templates and the models talk to JSON services that live in the Rails backend. The user doesn't see a page load until they need to leave the page to do something else. The experience is quite nice.

You can certainly take that example and render your templates server-side. I wouldn't go as far as to render every instance of the template server-side because templating engines (including the one built into Backbone/Underscore) are so powerful. But, if you wanted to seed your templates with server-side rendering, I could see how that might be useful.

0

精彩评论

暂无评论...
验证码 换一张
取 消