Book Image

JavaScript at Scale

By : Adam Boduch
Book Image

JavaScript at Scale

By: Adam Boduch

Overview of this book

Have you ever come up against an application that felt like it was built on sand? Maybe you've been tasked with creating an application that needs to last longer than a year before a complete re-write? If so, JavaScript at Scale is your missing documentation for maintaining scalable architectures. There's no prerequisite framework knowledge required for this book, however, most concepts presented throughout are adaptations of components found in frameworks such as Backbone, AngularJS, or Ember. All code examples are presented using ECMAScript 6 syntax, to make sure your applications are ready for next generation browsers.
Table of Contents (12 chapters)
11
Index

How routers work


Now it's time for us to dig a little deeper into routers. We want to know the responsibilities of a router, and what it's lifecycle looks like when the URI changes. Essentially, this amounts to the router taking the new URI and figuring out if it's something the router is interested in. If it is, then it triggers the appropriate route events with the parsed URI data as arguments.

Understanding the role of routers at a low-level is important for scaling our application because the more URIs we have, and the more components we have responding to these route events, the more potential for scaling issues. When we know what's happening with the router lifecycle, we can make the appropriate scaling trade-offs in response to scaling influencers.

Router responsibilities

A simplistic view of a router is just a map—there's routes, string or regular expression pattern definitions, which map to callback functions. What's important is that this process is fast, predictable, and stable....