Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTom de Visser
1,357 PointsMiddleware vs performance
Andrew is explaining that every request goes through all the middleware, including all the routes. Does this mean that the more routes you have, the slower your app becomes?
For instance, if you have a website with 100 pages, and someone requests the page that is at the bottom of your router, does it take longer to load than e.g. the homepage, as it has to check the route against every piece of middleware code?
2 Answers
Travis Alstrand
Treehouse TeacherHe explains that once it starts going through the routes, it checks the path and only executes if there is a match. I don't think that this would bog down performance time to anything we can notice but I guess to some extent you're correct. It's just not wasting the time of actually going through the entire route's code if there is not a match.
Michael Kristensen
Full Stack JavaScript Techdegree Graduate 26,251 PointsIn essence, yes, the more code you have, the longer it will take to execute; that is always the case.
But, as Travis describes, this type of middleware depends on a certain URL route being active, so it can be described as something like if
statements all the way through, that only execute the renders and other functions, on specific routes.