Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emberjs, server side vs client side, All in?

Tags:

I have been looking into Ember.js, and it looks really great, but one thing that concerns me, and that I can't get my mind around it, is if I start using it on an already running project.

Will I eventually have to move everything client side, and make my application a single page application at some point?

let me clarify...

So far the best way to communicate between client and server using Ember is REST. and that looks great, but what I don't like is having all the templates loaded for the first time. and moving all the logic in my server to the client (or am I getting all of this wrong?), cause it looks like my server side will become a logic-less REST API.

Also, I'm using Yii Framework which has some JavaScript (Ajax enabled) components like grids. how can I have ember interact with all of this on navigation without having to rewrite a bunch of stuff already working on my application?

I'm on the login page (or state), and then after login in, I have to display a grid, that is just easy with Yii, and a full page load, but If I am using Ember, how can I have my grid display as it normally would? do I have to pre-load a handlebar template for the grid, and also the JavaScript that controls it?

like image 936
Asgaroth Avatar asked Dec 26 '12 22:12

Asgaroth


People also ask

Which is better server-side or client-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 Ember JS client-side?

Ember. js is a free JavaScript client-side framework used to design web apps, and it is open source.

Is Ember server side rendering?

ember serve can serve render your app on server side as well.

What is client-side versus server-side?

Client-side developers focus on creating the parts of a website or application that users can see, such as visual design elements and web page layouts. Server-side developers focus more on behind-the-scenes components like how an application transmits data to a server.


2 Answers

No, you should not move everything to client side, especially authentication and validation that could be bypassed otherwise.

What you move to Emberjs is the yii-s View part of MVC, controller will output i.e JSON.

That Data then gets mapped to Embers Model part through Ember routing and controllers etc.

Since you are replacing Yii's presentation logic with ember you should not use Yii's UI classes like CGridView. Mixing them might be possible but that does not seem like a good idea. You have to run your own in Ember.

http://www.yiiframework.com/wiki/409/ember-js-with-yii-rest-backend-demo-application/

like image 183
Imre L Avatar answered Sep 22 '22 06:09

Imre L


Just to add a Yii perspective here. A lot of the "magic" of grid views/lists happens within the data provider (for complex searching, sorting and filtering) and by having the data formatted with parsed fields on models.

So you could utilise the same concepts server side and just output the final JSON, paginated and all, from within your own widget; or even just override the grid view and output json rather than the view after all the data/configuration processing.

Once you've got JSON down rather than HTML it's very easy to replicate the front end of the grid, there's really not much functionality going on there.

This might not be ideal, but it means you don't have to move all logic for pagination, searching and filtering to client side.

TL;DR;
Override the Yii widgets which you already have functionality built for, and use them to output JSON rather than HTML.

like image 44
Paystey Avatar answered Sep 24 '22 06:09

Paystey