[ 5 posts ]

Marc

YUI Contributor

  • Offline
  • Profile

App: how to acivate the current view, with server render

Post Posted: Wed Aug 01, 2012 11:55 am
+0-
Hi,

I am developing a YUI App that uses Handlebars with both dynamic and server side rendering support.

My homepage is a list of items. When I first load the page, I want server side rendering to be used, because it's faster. On subsequent pagination etc, I want to use client side/json rendering.

I'm just wondering how to set activeView when the content is rendered server side. I want to avoid reloading the content as a JSON call if it's already there.

Cheers,
Marc

Eric Ferraiuolo

YUI Developer

  • Username: ericf
  • Joined: Mon Jan 12, 2009 8:26 pm
  • Posts: 380
  • Location: Boston, MA
  • Twitter: ericf
  • GitHub: ericf
  • Gists: ericf
  • IRC: eric_f
  • YUI Developer
  • Offline
  • Profile

Re: App: how to acivate the current view, with server render

Post Posted: Wed Aug 01, 2012 2:41 pm
+0-
Marc,

This is a great question. I've been experimenting with some different approaches of solving this with the hope that we can provide a streamlined solution in YUI.

The basic idea behind the approaches I've been taking is to serialize the data the server is using to render the page (the models and model lists) to JSON, and dump that data into a <script> element within the HTML document the server is creating. If you're Gzipping the HTML pages (which you should) the amount of extra KB-weight will be minimal as gzipping is good at handling duplicate strings. Then the JavaScript running in the browser can revive that state and take over from there.

You can see this being done in Photos Near Me:

Server serializes the data it's using to render the HTML:
https://github.com/ericf/photosnear.me/ ... s#L130-147

Placeholders in the HTML for that data:
https://github.com/ericf/photosnear.me/ ... ars#L33-53

Client-side JavaScript reviving state and taking control:
https://github.com/ericf/photosnear.me/ ... rs#L55-102

I hope that helps guide you to something that will work for your app. Once this pattern becomes more fully baked and support widgets revivification through the same conduit, I hope to make it a feature of YUI.

Also it's really great to see you taking this approach of utilizing both the server and client to make your app awesome :)

Marc

YUI Contributor

  • Offline
  • Profile

Re: App: how to acivate the current view, with server render

Post Posted: Thu Aug 02, 2012 6:39 am
+0-
Hey Eric,

Thanks for that reply. That sounds like a workable solution although putting the hard-code data into the html seems a bit inelegant (but so is putting in handlebar templates). Wouldn't it be cool if we could reference content in script references by id?

But I would think that access to some shortcut would be a better solution. Something that allows you to say in stead o .dispatch(). .dispatch({render:false}), so that rendering is bypassed but a certain view does become active and all associated events also.

Eric Ferraiuolo

YUI Developer

  • Username: ericf
  • Joined: Mon Jan 12, 2009 8:26 pm
  • Posts: 380
  • Location: Boston, MA
  • Twitter: ericf
  • GitHub: ericf
  • Gists: ericf
  • IRC: eric_f
  • YUI Developer
  • Offline
  • Profile
Tags:

Re: App: how to acivate the current view, with server render

Post Posted: Thu Aug 02, 2012 7:38 am
+0-
mschipperheyn wrote:
Thanks for that reply. That sounds like a workable solution although putting the hard-code data into the html seems a bit inelegant (but so is putting in handlebar templates). Wouldn't it be cool if we could reference content in script references by id?


I'm not sure I follow you, can you elaborate on what you mean and how you'd do it differently?

mschipperheyn wrote:
But I would think that access to some shortcut would be a better solution. Something that allows you to say in stead o .dispatch(). .dispatch({render:false}), so that rendering is bypassed but a certain view does become active and all associated events also.


That's what this is doing, it's calling `showView()` and passing `render: false` as an option. Which tells the Y.App instance to not render the view (since it is already rendered by the server.)

Marc

YUI Contributor

  • Offline
  • Profile

Re: App: how to acivate the current view, with server render

Post Posted: Thu Aug 02, 2012 7:45 am
+0-
Huh, ok. Then I should be good to go. I guess I misunderstood you. I'll have a another look. Struggling with accessing parent scope right now.
  [ 5 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum