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

Mapping resources to URIs

It's time to look at URIs in action. The most common form we'll find URIs in, are as links inside our application. At least, that's the idea; to have an application that's well connected. While the router understands what to do with URIs, we are yet to look at all the places where these links need to be generated and inserted into the DOM.

There are two approaches to generate links. The first is a somewhat manual process that requires the help of template engines and utility functions. The second takes a more automated approach in an attempt to scale the manageability of many URIs.

Building URIs manually

If a component renders content in the DOM, it potentially builds URI strings and adds them to link elements. This is easy enough to do when there's only a handful of pages and URIs. The scaling issue here is that the page count and URI count found in JavaScript applications are complimentary—lots of URIs means lots of pages and vice-versa.

We can use the router pattern...