Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Backbone.js for a multi-page web app?

I've always used Backbone's routes (#!/blah)

But I realize that in order to get indexed by Google, you need to provide a non-javascript version of the site.

I don't like to write code twice. So, I would rather build a multi-page app instead of a single page web app.

Backbone.js provides me with the "structure" so my javascript does not turn into sphagetti mess. But , I'm completely clueless on how to build multi-page apps using Backbone.

Do you include the main.js file on every page render? What about routes? How do you deal with that? How do you deal with modularizing, etc?

I wish there was a tutorial on how to build multi-page javascript apps using Backbone.

like image 986
TIMEX Avatar asked Feb 05 '13 23:02

TIMEX


People also ask

Do people still use Backbone JS?

Backbone. Backbone has been around for a long time, but it's still under steady and regular development. It's a good choice if you want a flexible JavaScript framework with a simple model for representing data and getting it into views.

Is Backbone JS frontend or backend?

Backend Synchronization BackboneJS is use with the front-end and back-end systems, allows the synchronization with the backend to provide support to RESTful APIs.

Is backbone a MVC?

Backbone. js is a model view controller (MVC) Web application framework that provides structure to JavaScript-heavy applications. This is done by supplying models with custom events and key-value binding, views using declarative event handling and collections with a rich application programming interface (API).

What is backbone JS comparable to?

Vue. js, React, AngularJS, Angular 2, and Ember. js are the most popular alternatives and competitors to Backbone. js.


1 Answers

There are a lot of considerations for doing something like this, but here are two keys one:

Serving the page

You probably want to have your web server route everything to the serve the same static page (assuming it is static assets). This means that everything in http://yourdomain.com/* will serve /var/www/yourdomain.com/index.html. Once the static page is loaded, the JS on that page will decide what to do given the url.

Push State

To do your routing, you can still use backbone routing, but don't use hashbangs (the #!/blah style urls). See http://backbonejs.org/#History for instance. This will allow you to navigate to real URLs without actually needing a page refresh. If the browser doesn't support a pushState, everything will still work, but it will reload the page.

like image 166
Jamie Wong Avatar answered Oct 24 '22 04:10

Jamie Wong