Search code examples
node.jsbackbone.jsrequirejs

Backbone with Multipage node app strategy


I have a question regarding the node app that I want to build.
Before starting on the development, I've written a clear document that splits up my app into different components:

  • Home
  • Search
  • User profile
  • Dashboard etc...

Each of these modules may in turn consist of different submodules.
As every module in my app works quite independently (although there are common, reusable components), I decided to render the main page for each of the modules from the server using Express.

Each of the pages that I want to render is highly interactive in the field of DOM interaction and event driven view updates, so I want to go with Backbone for this (using push state for loading submodules dynamically for the nested url's), in combination with requirejs for asynchronous module loading.

The thing I wonder about is if it is okay to include a minified file for each of the pages that I render from the server with express. It seems that this causes quite some overhead, because for each module loaded all the libraries need to be included again (backbone, underscore, jquery, and others).

Is there a common solution to this problem, and will this (in your experience) cause unacceptable performance issues?


Solution

  • What we end up doing with a similar multi page app structure is we break the build to separate "common.js" file that contains all the shared modules, and "main-[module-name].js" files for page specific code, and load it with 2 separate script tags per page

    I don't know that it has actual significant perf impact. I am guessing that not really, unless you have some large libraries in your project

    Take a look at the multi page config example for requirejs

    My $0.02