Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 1258

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 62k
Author
Asked: November 25, 20242024-11-25T06:29:09+00:00 2024-11-25T06:29:09+00:00

Difference between normal links & tag links in Next.js

  • 62k

Today in this blog we will talk about the effect of using “a” tag & “Link” tag in Next.js. Are they really different from each other?
Sure they are, let me explain.

Normal Links

When you use normal links like this:

<a href="./users">Click Here</a> 
Enter fullscreen mode Exit fullscreen mode

every time that you click the link and navigate to other pages, you call a request to all the files and all of them will download again. That's something we don't want of course. so look at this folder structure that I have to understand better:

Image description
In this structure, as you can see in my app folder I have a page.tsx file and a folder named “folder” that contains F1.tsx.
In the page file, I have below code that is just a simple page:

import React from "react";  async function page() {   return (     <div className="p-[1rem]">       <h1>Hello World</h1>     </div>   ); }  export default page;  
Enter fullscreen mode Exit fullscreen mode

And in the F1 file, I have this code that as you see it's just a simple button with “a” tag in it:

import Link from "next/link"; import React from "react";  function F1() {   return (     <button className="py-[0.5rem] px-[2.5rem] bg-gray-800 rounded-[0.75rem]">       <a href="/users" className="text-white">         click       </a>     </button>   ); }  export default F1; 
Enter fullscreen mode Exit fullscreen mode

When you click that “a” tag you will navigate to the user's file page and everything should work fine. But let's open the Network tab real quick.

Image description
It's normal, right? we have all the necessary files in here.
OK now clear the Network log and click the button to navigate to the user page:

Image description
By clicking the button we go to “http://localhost:3000/users” & this is our Network log:

Image description
As I told you we redownloaded all the unnecessary files again. and we don't want that. So what is the solution?

Tag Links

Simple, we are just going to use “Link” instead of “a” tag. Like this:

import Link from "next/link"; import React from "react";  function F1() {   return (     <button className="py-[0.5rem] px-[2.5rem] bg-gray-800 rounded-[0.75rem]">       <Link href="/users" className="text-white">         click       </Link>     </button>   ); }  export default F1;  
Enter fullscreen mode Exit fullscreen mode

Now again open the Network tab, we have our files downloaded once. Click clear log like before and navigate to the F1 file using the button. Now if you see the log we just downloaded our necessary files and not all of the files again.

Image description
So to wrap up by using the “a” tag we download all the files again & again but with the “Link” tag we just download all the files once and on every page we just download what we need.

This small change may not seem handy but in the big projects, it will help you build a website or app with better performance and of course a faster one!
If this blog helped you please like and also feel free to share ANY opinion in the comments section. Thanks for reading🙏.

javascriptprogrammingreactwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.