Differences between routes and pages

Routes and pages are very similar concepts and are often used interchangeably by Backbone programmers. This is natural since routes are essentially just the Backbone implementation of pages. However, there are important differences between the two, at least when you compare the pages of a multi-page website to the routes of a Backbone single-page application.

In traditional, multi-page websites, each new page that the user visits requires you to make a new request to the site's server. In a Backbone-powered site, however, the user can navigate through as many pages (routes) as they want, making new requests only when it is necessary to fetch new data. This feature alone accounts for a significant increase in speed on a Backbone-powered site.

Another important difference is that standard web pages trigger an entire page load, whereas routes trigger only a specific JavaScript function. This means that unlike a traditional application, which has to limit the number of pages (and thus the number of HTTP requests) it makes, routes can be used for just about any possible change in state. Routes can be used in a similar way to traditional web pages, or they can be used for much smaller changes to a page. They can even (rarely) be used when there is no change to the DOM at all.

Of course, while Backbone routes have many advantages, they also have some downsides. The most important downside is that because they do not refresh the page, existing DOM elements, style changes, and event bindings are not cleared automatically. This means that you will need to handle these clean-up tasks yourself. Luckily, this isn't very difficult to do, especially if you rely on a page view, which we will introduce shortly.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.42.81