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 trialPeter Kolawa
36,765 PointsWhich one: .param() or route method is more efficient? Andrew as always messed it up... ;/
To be honest: I hate Andrews tutorials. They are always messed up, too long and hard to stand until the end.
But despite that fact: is dealing with one .param() method for URL params more efficient than repeating ourselves in every single router endpoint method?
1 Answer
Jesus Mendoza
23,289 PointsHey Peter,
In my opinion, it's the same when it comes to performance, but better when it comes to code readability.
Lets say you want to query the database everytime you enter a route with an expecific param. Performance wise you will make a call to the database everytime you hit the route with that expecific param, no matter if you declare it on the params route or the individual route.
But when it comes to code readability, you only write that code once (on the param route) instead of having to write it on every route with that expecific param.
That's just my opinion and I might be wrong!
Have a nice day