1

In my app, i have no.of pages. each pages have a separate view for them. But in the header part i need to show the user name on all views rendering.. what would be the best practice for that..

i came across with some of options saying..

1. render the header view even before the router starts

2. use the routers '*' - notation to call the header view always.

3. keep the header view as a sub view of all page views - and keep call header view on all page view..

what would be the correct way...please any one suggest me the best way.

Sergey
  • 5,208
  • 25
  • 36
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
  • 1
    May be I did not get your full question but assuming we are talking here of single page app, it seems obvious to me to have header view in your page and keep refreshing (rendering) ur other body tags based on user actions. – Nitin Agrawal Aug 07 '13 at 05:02
  • Mine is single page app, but it has multiple pages. I show all pages without refreshing and loading using different views – 3gwebtrain Aug 07 '13 at 05:10
  • 1
    yeah… and that's actually the point of single-page app right? you don't need to reload every part of the page when it is going to stay intact throughout your app right? Have a look at this: http://backbonejs.org/docs/todos.html – j03w Aug 07 '13 at 05:13
  • r u not using seprate files .js for header and body tags?? if yes it is simple to just load body .js files not header.js. If not you might hv to reconsider your design.. – Nitin Agrawal Aug 07 '13 at 05:49

1 Answers1

1

Have a layout view that contains the header and gets rendered only once. Then just render the interior portion of the document as you navigate. Changing the URL and triggering a new route does not always imply the entire DOM needs to re-render. Keep your DOM changes as small as possible. Also study the idea of nested views like you get with Backbone.Marionette for another approach.

Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
  • can you explain me this part " header and gets rendered only once"..? (because it should not go off on refresh the page ) – 3gwebtrain Aug 07 '13 at 06:52
  • You can handle that by rendering the layout (header/footer) only in router initialize and then rendering the body in the route handlers. You can also just check if the header selector exists in the DOM and skip rendering if it's already there if you can't get your rendering logic to work consistently just via the router mechanism. – Peter Lyons Aug 07 '13 at 15:16