<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Emdadul Islam</title>
    <description>The latest articles on DEV Community by Emdadul Islam (@bekon0700).</description>
    <link>https://dev.to/bekon0700</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1355474%2Fe3197817-d521-4883-90e3-cd86189db5da.jpeg</url>
      <title>DEV Community: Emdadul Islam</title>
      <link>https://dev.to/bekon0700</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bekon0700"/>
    <language>en</language>
    <item>
      <title>[Boost]</title>
      <dc:creator>Emdadul Islam</dc:creator>
      <pubDate>Wed, 12 Mar 2025 17:21:56 +0000</pubDate>
      <link>https://dev.to/bekon0700/-34hh</link>
      <guid>https://dev.to/bekon0700/-34hh</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/bekon0700" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1355474%2Fe3197817-d521-4883-90e3-cd86189db5da.jpeg" alt="bekon0700"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/bekon0700/--6lg" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;🔥 𝗙𝗿𝗼𝗻𝘁𝗲𝗻𝗱 𝗗𝗲𝘃𝗲𝗹𝗼𝗽𝗲𝗿𝘀: 𝗛𝗼𝘄 𝘁𝗼 𝗧𝗵𝗶𝗻𝗸 𝗟𝗶𝗸𝗲 𝗮𝗻 𝗘𝘅𝗽𝗲𝗿𝘁 𝗳𝗿𝗼𝗺 𝗗𝗮𝘆 𝗢𝗻𝗲! 🚀&lt;/h2&gt;
      &lt;h3&gt;Emdadul Islam ・ Mar 12&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#frontend&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#react&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#css&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>frontend</category>
      <category>react</category>
      <category>css</category>
    </item>
    <item>
      <title>🔥 𝗙𝗿𝗼𝗻𝘁𝗲𝗻𝗱 𝗗𝗲𝘃𝗲𝗹𝗼𝗽𝗲𝗿𝘀: 𝗛𝗼𝘄 𝘁𝗼 𝗧𝗵𝗶𝗻𝗸 𝗟𝗶𝗸𝗲 𝗮𝗻 𝗘𝘅𝗽𝗲𝗿𝘁 𝗳𝗿𝗼𝗺 𝗗𝗮𝘆 𝗢𝗻𝗲! 🚀</title>
      <dc:creator>Emdadul Islam</dc:creator>
      <pubDate>Wed, 12 Mar 2025 17:21:21 +0000</pubDate>
      <link>https://dev.to/bekon0700/--6lg</link>
      <guid>https://dev.to/bekon0700/--6lg</guid>
      <description>&lt;p&gt;When starting as a 𝗷𝘂𝗻𝗶𝗼𝗿 𝗳𝗿𝗼𝗻𝘁𝗲𝗻𝗱 𝗱𝗲𝘃𝗲𝗹𝗼𝗽𝗲𝗿, debugging and understanding issues can be overwhelming. Often, we rely on senior developers for guidance. But what if you could approach problems like an expert from day one? Here are some key 𝗱𝗲𝗯𝘂𝗴𝗴𝗶𝗻𝗴 𝗮𝗻𝗱 𝗼𝗽𝘁𝗶𝗺𝗶𝘇𝗮𝘁𝗶𝗼𝗻 𝘀𝘁𝗿𝗮𝘁𝗲𝗴𝗶𝗲𝘀 to level up your frontend skills:&lt;/p&gt;

&lt;p&gt;🔍 Debugging Like a Pro&lt;br&gt;
✅ 𝗙𝗶𝗻𝗱 𝘁𝗵𝗲 𝗘𝗻𝘁𝗿𝘆 𝗣𝗼𝗶𝗻𝘁&lt;br&gt;
When a website feature isn’t working, identify which file or component is responsible. Inspect the page for unique values (like IDs) to trace it back to the source file.&lt;/p&gt;

&lt;p&gt;✅ 𝗨𝘀𝗲 𝗥𝗼𝘂𝘁𝗶𝗻𝗴 𝗳𝗼𝗿 𝗤𝘂𝗶𝗰𝗸 𝗡𝗮𝘃𝗶𝗴𝗮𝘁𝗶𝗼𝗻&lt;br&gt;
Instead of always asking seniors, leverage 𝗿𝗼𝘂𝘁𝗶𝗻𝗴 to locate the exact file serving a page. This will make you self-sufficient and speed up your debugging process.&lt;/p&gt;

&lt;p&gt;✅ 𝗠𝗮𝘀𝘁𝗲𝗿 𝘁𝗵𝗲 𝗜𝗻𝘀𝗽𝗲𝗰𝘁 𝗘𝗹𝗲𝗺𝗲𝗻𝘁 &amp;amp; 𝗖𝗼𝗻𝘀𝗼𝗹𝗲 𝗟𝗼𝗴𝘀&lt;br&gt;
Your best friends as a frontend developer are the 𝗖𝗼𝗻𝘀𝗼𝗹𝗲 𝗮𝗻𝗱 𝗘𝗹𝗲𝗺𝗲𝗻𝘁𝘀 𝘁𝗮𝗯. &lt;br&gt;
• Use console logs to track issues without getting lost in complex code. &lt;br&gt;
• Plan your design layout by inspecting elements before jumping into code.&lt;/p&gt;

&lt;p&gt;✅ 𝗡𝗲𝘁𝘄𝗼𝗿𝗸 𝗧𝗮𝗯: 𝗬𝗼𝘂𝗿 𝗦𝗲𝗰𝗿𝗲𝘁 𝗪𝗲𝗮𝗽𝗼𝗻&lt;br&gt;
This tool helps you debug API calls efficiently. Suppose an API is unintentionally called twice per action—using the Network tab, you can identify and fix it, impressing your team in the next Scrum meeting.&lt;/p&gt;

&lt;p&gt;✅ 𝗢𝗽𝘁𝗶𝗺𝗶𝘇𝗲 𝗔𝗽𝗽𝗹𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗦𝘁𝗼𝗿𝗮𝗴𝗲&lt;br&gt;
The Application tab (Local Storage) can reduce backend dependency and improve user experience with smart caching strategies.&lt;/p&gt;

&lt;p&gt;⚡ 𝗤𝘂𝗶𝗰𝗸 𝗢𝗽𝘁𝗶𝗺𝗶𝘇𝗮𝘁𝗶𝗼𝗻 𝗧𝗶𝗽𝘀&lt;br&gt;
🔹 𝗨𝘀𝗲 𝗨𝗻𝗶𝗾𝘂𝗲 𝗶𝗱 𝗔𝘁𝘁𝗿𝗶𝗯𝘂𝘁𝗲𝘀 in components for faster debugging.&lt;br&gt;
🔹 𝗔𝘃𝗼𝗶𝗱 𝘂𝗻𝗻𝗲𝗰𝗲𝘀𝘀𝗮𝗿𝘆 𝗹𝗼𝗼𝗽𝘀—if you need only a few specific values, access them directly instead of iterating through the entire dataset.&lt;br&gt;
🔹 𝗟𝗮𝘇𝘆 𝗹𝗼𝗮𝗱 𝗹𝗼𝘄𝗲𝗿-𝗽𝗮𝗴𝗲 𝘀𝗲𝗰𝘁𝗶𝗼𝗻𝘀 to improve initial page load speed and reduce backend strain.&lt;br&gt;
🔹 𝗠𝗶𝗻𝗶𝗺𝗶𝘇𝗲 𝗛𝗧𝗠𝗟 𝗘𝗹𝗲𝗺𝗲𝗻𝘁𝘀 to reduce document size and improve performance.&lt;br&gt;
🔹 𝗪𝗿𝗶𝘁𝗲 𝗰𝗼𝗻𝗰𝗶𝘀𝗲 𝗖𝗦𝗦 (shorthand properties) to optimize stylesheets.&lt;br&gt;
🔹 𝗡𝗲𝘃𝗲𝗿 𝘄𝗿𝗶𝘁𝗲 𝗰𝗼𝗱𝗲 𝘄𝗶𝘁𝗵𝗼𝘂𝘁 𝘂𝗻𝗱𝗲𝗿𝘀𝘁𝗮𝗻𝗱𝗶𝗻𝗴 𝗶𝘁—it may work today but will cause major issues later.&lt;/p&gt;

&lt;p&gt;By implementing these strategies, you’ll start 𝘁𝗵𝗶𝗻𝗸𝗶𝗻𝗴 𝗹𝗶𝗸𝗲 𝗮 𝘀𝗲𝗻𝗶𝗼𝗿 𝗱𝗲𝘃𝗲𝗹𝗼𝗽𝗲𝗿 while still in your junior phase! 🚀&lt;/p&gt;

&lt;p&gt;Do you have any 𝗱𝗲𝗯𝘂𝗴𝗴𝗶𝗻𝗴 𝘁𝗿𝗶𝗰𝗸𝘀 that helped you as a frontend developer? Drop them in the comments! 👇&lt;/p&gt;

&lt;h1&gt;
  
  
  FrontendDevelopment #WebPerformance #WebOptimization #DebuggingTips #WebDevelopment #LazyLoading #CSSOptimization #JavaScript #FrontendTips #CareerGrowth
&lt;/h1&gt;

</description>
      <category>frontend</category>
      <category>react</category>
      <category>css</category>
    </item>
    <item>
      <title>How to Optimize API Requests with Refresh Tokens and Axios Interceptors in Next.js</title>
      <dc:creator>Emdadul Islam</dc:creator>
      <pubDate>Sat, 16 Mar 2024 18:14:32 +0000</pubDate>
      <link>https://dev.to/bekon0700/axios-interceptor-for-jwt-validation-3065</link>
      <guid>https://dev.to/bekon0700/axios-interceptor-for-jwt-validation-3065</guid>
      <description>&lt;p&gt;We all used JWT at least once in our lives. In the minimum scenario we use JWT token for API requests to get any data. This kind of token is know as access token(AT) and it can store some property. But the &lt;strong&gt;most important one is expire time&lt;/strong&gt;. So, we have to store that AT in the browser so that it can be send again when we make a request to the API. The work can be done from here but the problem arise if the token is valid for a long period of time. For this issue developer started to use refresh token(RT). &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Access Token:&lt;/strong&gt; An access token is short lived token that is send as a bearer token inside the authorization header. The expire time is in between 1 minute to 15 minutes maximum.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Refresh Token:&lt;/strong&gt; When an access token is expired, we make a call to a specific route for new access token. This route take refresh token as authorization header and do some serious validation to return an access token for API calls within the website and a new refresh token to store for the user in the browser to get the next new access token from the '/refresh' route.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For the front end call we usually use Axios or fetch API for calling the external API for data. For this guideline I am gonna use Axios and NextJS as a reference.&lt;/p&gt;

&lt;p&gt;On the base line, Axios is used to make HTTP request to an API and get HTTP response in return. Interceptors are like middleman for this request and response. Whenever you gonna make a request its gonna go through the interceptor first. In that interceptor you can change the header object as you like. In our case AT is need to be add in the authorization header like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NGYwNzYzOGFlNjg4MDY4YzY1ODBkNzMiLCJwaG9uZSI6IjAxNSIsInJvbGUiOiJTVVBFUl9BRE1JTiIsImlhdCI6MTcxMDUwMzQ5NSwiZXhwIjoxNzExMTA4Mjk1fQ.STh0ZBiQVV
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For our convenience, we make a fetcher function. that gonna get the access token from the local storage or cookie and add that token into the authorization header. That gonna look like something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fus76p8tci6av55ki6bmd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fus76p8tci6av55ki6bmd.png" alt="code preview of the fetcher function" width="800" height="577"&gt;&lt;/a&gt;&lt;br&gt;
Here the &lt;strong&gt;checkAuth()&lt;/strong&gt; function get the header as option. In my application it was a hook that gonna utilize the interceptor mechanism of Axios.&lt;/p&gt;

&lt;h2&gt;
  
  
  Axios Interceptor
&lt;/h2&gt;

&lt;p&gt;Axios interceptor is like a middleware that gonna intercept the request and response of a http request and modify the header or data as per requirement.&lt;/p&gt;

&lt;p&gt;So we made a interceptor that gonna get access token and evaluate if it is expired or not. If it is expired then it gonna call the &lt;strong&gt;"/refresh-token"&lt;/strong&gt; route to get the new valid access token along with refresh token.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9hwc5f5r9uhm1ewf5j4p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9hwc5f5r9uhm1ewf5j4p.png" alt="code preview of the axios interceptor" width="800" height="1633"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, I used next auth for my project. &lt;strong&gt;NextAuth provides&lt;/strong&gt; a hook called &lt;strong&gt;useSession()&lt;/strong&gt;. This hook returns the data we stored in the session and a authentication state as status. In the &lt;strong&gt;useEffect()&lt;/strong&gt; hook we called the request interceptor first. First argument of this function is callback function and the second argument takes the error handler. In brief we checked the AT validity then took a decision. if we need to fetch the refresh token we call the &lt;strong&gt;useRefreshToken()&lt;/strong&gt; hook to get the new refresh token and set the info in the session storage using &lt;strong&gt;useSession()&lt;/strong&gt; hook. &lt;/p&gt;

&lt;p&gt;But the &lt;strong&gt;problem arise&lt;/strong&gt; when a page has 5 or 10 API call and all of them call the fetcher function thus the &lt;strong&gt;useAxiosAuth()&lt;/strong&gt; hook. So all of them got the expired access token and call the &lt;strong&gt;/refresh-token&lt;/strong&gt; route to get the refresh token. &lt;/p&gt;

&lt;p&gt;To resolve this problem we introduce the &lt;em&gt;promise based request solver&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdx4278x0vrj2q5srhm44.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdx4278x0vrj2q5srhm44.png" alt="code preview of the queue of the pending requests" width="800" height="650"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;addRequestToQueue()&lt;/strong&gt; will take all the request with invalid access token and place them in the &lt;strong&gt;refreshQueue[]&lt;/strong&gt;. After that we will fetch the new access token from the &lt;strong&gt;'/refresh-token'&lt;/strong&gt; route. Once we got all the AT. then we will resolve all the pending request that is waiting for fetching in the &lt;strong&gt;refreshQueue[]&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Impact Before and After Implementing the Solution:&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  🚨 &lt;span&gt;Before Optimization:&lt;/span&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;5 API calls&lt;/strong&gt; trigger:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;5 requests&lt;/strong&gt; to the &lt;code&gt;/refresh-token&lt;/code&gt; route.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;5 invalid API calls&lt;/strong&gt; to the final API using expired access tokens.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Total server requests&lt;/strong&gt;: &lt;strong&gt;25 requests&lt;/strong&gt; for every 5 API calls made.&lt;/p&gt;

&lt;p&gt;If you have &lt;strong&gt;1,000 users&lt;/strong&gt;, that means &lt;strong&gt;25,000 unnecessary requests&lt;/strong&gt; to the backend server! 😵‍💫 😵 &lt;/p&gt;

&lt;h4&gt;
  
  
  ✅ &lt;span&gt;After Optimization:&lt;/span&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;5 API calls&lt;/strong&gt; now result in:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;1 request&lt;/strong&gt; to the &lt;code&gt;/refresh-token&lt;/code&gt; route to obtain a new access token.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;5 valid API calls&lt;/strong&gt; to the final API with the new, valid access token.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Total server requests&lt;/strong&gt;: &lt;strong&gt;6 requests&lt;/strong&gt; for every 5 API calls made.&lt;/p&gt;

&lt;p&gt;For &lt;strong&gt;1,000 users&lt;/strong&gt;, this means only &lt;strong&gt;6,000 requests&lt;/strong&gt;, drastically reducing server load.🎇 🎊&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Key Benefit:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;By implementing this optimization, there’s a &lt;strong&gt;76% reduction&lt;/strong&gt; in backend API calls! This leads to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reduced server load&lt;/strong&gt; and &lt;strong&gt;faster response times&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improved user experience&lt;/strong&gt; with minimal delay.&lt;/li&gt;
&lt;li&gt;A more &lt;strong&gt;scalable solution&lt;/strong&gt; for high-traffic applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is my first writing in my entire career, I apologize if anything is wrong. Suggest me the point of improvements, that I will truly appreciate. &lt;/p&gt;

&lt;p&gt;Thank you.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>nextjs</category>
      <category>axios</category>
      <category>interceptor</category>
    </item>
  </channel>
</rss>
