Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7702995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:21:30+00:00 2026-05-31T23:21:30+00:00

I am building a small app that uses backbone.js on the client side, node.js/socket.io

  • 0

I am building a small app that uses backbone.js on the client side, node.js/socket.io on the server side, and the connection goes trough websockets only.

Now how would I make my setup if I want to get the template and the data at once.

  1. I do a fetch() in the router, which gets the data and the template. With this I construct my view -> collection -> model.

  2. I do a fetch() in the view itself. (Maybe in the initialize)

===

I want to extend this problem with the following.

Let’s say a user browses to http://mysite.com/products and the user is not logged in yet, he is not allowed to view the page. He has to be rerouted to /login.

The problem is I can only verify this on the server, so the server has to send back the correct data whether the user is logged in or not, and backbone.js has to deal with this.

Summarized:
I make a fetch to the server which will send back data + template html.

Backbone.js has to render the template with the data,

or reroute (Backbone.history.navigate('login', {trigger: true})) when the server sends back a flag.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:21:31+00:00Added an answer on May 31, 2026 at 11:21 pm

    You could use parse method in your Backbone collection for example :

    Collections.Products = Backbone.Collection.extend({
    
         url : '/products',
    
         parse : function (response) {
              //
              // you should return JSON from your server and the object must be smth like
              // { template : "<p>template for products</p>", data : productsInJSON }
              //
              if ( response.template && response.data ) {
                   this.trigger('template', response.template);
                   return response.data;
              } else {
                   return response;
              }
         }
    });
    
    Views.Page = Backbone.View.extend({
    
         initialize : function () {
              _.bind(this, 'render');
    
              var self = this;
    
              this.collection = new Collections.Products();
              this.collection.on('template', function(template) { 
                   self.render(template);
              });
         },
    
         render: function(template) {
              $("div#page").html(template);
         }
    
    });
    
    $(function() {
        window.app = {};
    
        window.app.view = new Views.Page();
    
        // here you are sending {template:true} to '/products' in your server
        window.app.view.collection.fetch( { data : { template : true } } );
    
    });
    

    If you are using socket.io, you should create a new Backbone.sync method for your requests.

    It is a little bit out of the Backbone philosophy and the integrated GET, PUT, POST, DELETE methods, so there will be a lot of coding.

    You could send a template for unlogged in users with no data for the collection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relatively small app that Im building using vb.net 2.0, and nant.
I am building small app that will only display products in various categories. And
I'm building a small app that calculate hash from any given file to multiple
Right now I'm building a small app that imports data from a spreadsheet and
I am building a small app primarily with socket io, however with a few
I have an asp .net webforms app that uses forms authentication. For a small
I'm building a small web app in PHP that stores some information in a
I'm building a web app that has a grid of many small scrollable divs
I'm building a web-app that handles internal emails and other frequent small-to-medium sized chunks
I'm building an HTTP server for Windows that uses IO Completion ports (IOCP). I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.