Book Image

JavaScript at Scale

By : Adam Boduch
Book Image

JavaScript at Scale

By: Adam Boduch

Overview of this book

Table of Contents (17 chapters)
JavaScript at Scale
About the Author
About the Reviewers

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....