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:
Do I have to use client-side templating?
Can I use BackboneJS to control pre-written server-side compiled html?
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.
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).
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.
Markup languages like HTML and CSS are interpreted by the browser on the client side.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With