Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am looking into Backbone JS and getting a little confused. I am used to compiling my page html on the server-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?

like image 708
wilsonpage Avatar asked Oct 12 '11 10:10

wilsonpage


People also ask

Which is better client-side or server side rendering?

Between the two options, server-side rendering is better for SEO than client-side rendering. This is because server-side rendering can speed up page load times, which not only improves the user experience, but can help your site rank better in Google search results.

Is HTML server-side or client-side?

Client-side code is written using HTML, CSS, and JavaScript — it is run inside a web browser and has little or no access to the underlying operating system (including limited access to the file system).

Should I use server side rendering?

If you wanted to serve Static Content only on your website, you need to use Server Side Rendering in this case. Static Content means no requests for dynamic data in most case. In this case, using SSR makes web pages load faster.

Is HTML processed by the client-side browser?

Markup languages like HTML and CSS are interpreted by the browser on the client side.


1 Answers

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.

like image 188
Brian Genisio Avatar answered Oct 04 '22 16:10

Brian Genisio