Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Express Basics Parameters, Query Strings, and Modularizing Routes Linking Around the Application

Forward instead of redirect in Express?

I know there is a way in Java to "redirect" the user to another page without him noticing called Forwarding.

In here we use a lot of redirects when clicking on "Next card". In the network tab in the dev tools you see 2 redirects before landing on the right page.

I was wondering if its possible to send the client to the right url without sending so many requests to the server.

Pug could handle some things but then you put a lot of logic in a template and that is actually not what i want.

So how would you implement it?

Kenneth Kim
Kenneth Kim
3,795 Points

Hi. Let me try something here as I am learning it just now myself. I believe it would still be the best practice since Right now we are dealing with a small app. app.js is the main router file and has references to other router files which I guess we can call it having a 'centralize' format or somewhat modular (maybe?). Also what you're saying can be done however i think it would involve a lot of code repetitions.

I hope this gave you an idea or two :)

Abraham Juliot
Abraham Juliot
47,341 Points

I think repeating one line of code is better than having a double redirect served to the client. If the exact url is known, I would use that instead of redirecting to a redirect.

Setting all that aside, using params for quizes and text based queries is overkill on client server communication. I think its better to serve the json data with the initial request and let client side javascript handle any text based quering without refreshing the page.

If there are alot images or large assets included with the json data, you can use lazy load or ajax to get it when its needed.

I think query params come in handy when the query itself should be used or shared as a direct link. Amazon is a good example.

Just my thoughts