<?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: Atena / Full stack developer</title>
    <description>The latest articles on DEV Community by Atena / Full stack developer (@atena).</description>
    <link>https://dev.to/atena</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1032225%2Fecefe356-c79f-4de2-84fc-99ce8c12af5c.png</url>
      <title>DEV Community: Atena / Full stack developer</title>
      <link>https://dev.to/atena</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/atena"/>
    <language>en</language>
    <item>
      <title>What is a Reverse Proxy/AI Gateway Doing Behind the Browser?</title>
      <dc:creator>Atena / Full stack developer</dc:creator>
      <pubDate>Mon, 30 Nov 2026 07:01:15 +0000</pubDate>
      <link>https://dev.to/atena/what-is-a-reverse-proxy-doing-behind-the-browser-5gpe</link>
      <guid>https://dev.to/atena/what-is-a-reverse-proxy-doing-behind-the-browser-5gpe</guid>
      <description>&lt;h2&gt;
  
  
  What is a reverse proxy?
&lt;/h2&gt;

&lt;p&gt;A reverse proxy is a doorman👮🖐️ between the browser and the application server. It takes each request on the server's behalf and passes it to the right server behind it. The only thing a user ever sees is the reverse proxy. The apps and containers behind it stay out of sight🙈.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What does a reverse proxy do when you open a website?
&lt;/h2&gt;

&lt;p&gt;When you open &lt;a href="https://example.com" rel="noopener noreferrer"&gt;https://example.com&lt;/a&gt;, the reverse proxy does four jobs before the page shows up💪. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It shows its certificate&lt;/li&gt;
&lt;li&gt;Unlocks the encrypted request&lt;/li&gt;
&lt;li&gt;Passes the request to the right container&lt;/li&gt;
&lt;li&gt;Locks the HTML that comes back before sending it to the browser. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The example here is a common setup: an app (say, Next.js) running in a Docker container behind the reverse proxy. We'll follow one request from the moment it arrives until the HTML goes back.&lt;/p&gt;

&lt;p&gt;Let's see how they work:&lt;br&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft7mvii83cv4fjge4laoe.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft7mvii83cv4fjge4laoe.png" alt="What Is a Reverse Proxy Doing Behind the Browser?" width="800" height="1076"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  1.  Look up the IP with DNS:
&lt;/h3&gt;

&lt;p&gt;The browser asks a DNS server, “What is the IP for example.com?” and gets back the server's IP (for example, 203.0.113.10). The reverse proxy is not involved yet.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  2.  Connect to port 443:
&lt;/h3&gt;

&lt;p&gt;The browser connects to that IP on port 443. A port is a numbered door into one server, and HTTPS normally uses 443. The reverse proxy is the first thing waiting at that door(Yay!finally👏).&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  3.  Show the certificate and share a key (the TLS handshake):
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The reverse proxy holds a public/private key pair&lt;/strong&gt; that was made ahead of time, when the certificate was set up. The only key made fresh for each connection is the session key you'll meet in a moment. &lt;/p&gt;

&lt;p&gt;The reverse proxy hands its certificate (which contains the public key) to the browser. The browser checks the certificate's domain name and expiry date, then makes a throwaway &lt;strong&gt;“session key”&lt;/strong&gt;, puts it in a box, locks the box with the public key, and sends it. &lt;/p&gt;

&lt;p&gt;A public key and a private key are a pair: a box locked with the public key can only be opened with the matching private key. &lt;strong&gt;So only the reverse proxy, which holds the private key, can open this box.&lt;/strong&gt; Nobody along the way can. &lt;/p&gt;

&lt;p&gt;The reverse proxy opens the box with its private key and takes out the session key. Now the browser and the reverse proxy hold the same session key, and everything after this is encrypted with it.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  4. Open the request and read it (TLS termination):
&lt;/h3&gt;

&lt;p&gt;Once the key is shared, the browser builds an HTTP request, locks it with the session key, and sends it. The reverse proxy opens it with the session key (decrypts it) and reads what is inside. The request is plain text like the one below. &lt;strong&gt;Only now does the proxy know which domain and which path it is for.&lt;/strong&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  5. Choose where to send it (routing):
&lt;/h3&gt;

&lt;p&gt;The reverse proxy uses the Host header (the domain the user typed) and the path to look up a destination in a table it was given, for example &lt;code&gt;example.com&lt;/code&gt; → &lt;code&gt;app:3000&lt;/code&gt;, and passes the request to that app. The destination is an address inside the server, not the public domain. It also adds the client's original IP to an &lt;code&gt;X-Forwarded-For header&lt;/code&gt;.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  6. The app builds the HTML:
&lt;/h3&gt;

&lt;p&gt;Next.js, running on Node.js inside the container, handles the request and sends HTML back to the reverse proxy.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  7. Lock it and send it back:
&lt;/h3&gt;

&lt;p&gt;The reverse proxy takes the HTML from the app (it isn't encrypted yet), locks it with the session key, and sends it to the browser. The browser opens it with the same key and shows the page(Phew, about time😮‍💨 That was a lot of key things...).&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Why lock everything so tightly?
&lt;/h2&gt;

&lt;p&gt;So many key things!🔑😮‍💨 Why do we need this process...? Actually, traffic between a browser and a server passes through many machines that belong to other people: Wi-Fi, routers, internet providers. If the connection isn't locked (plain HTTP), anyone along the way can do the following:&lt;br&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8n5tzqk56pdod29kh5r8.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8n5tzqk56pdod29kh5r8.png" alt="Why lock everything so tightly?" width="800" height="278"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  OK, then why two kinds of keys?
&lt;/h2&gt;

&lt;p&gt;A browser and a server that meet for the first time can't agree on a secret word ahead of time. So the browser locks a box with the public key, which is fine for anyone to see, and only the server holding the private key can open it. That is how the session key travels safely. Once it arrives, both sides use the same fast session key for the rest of the conversation.&lt;br&gt;
The certificate matters for the same reason. A fake server could hand over its own public key. The browser checks the certificate (the signature of a certificate authority such as Let's Encrypt, the domain name, and the expiry date) to decide whether the server is the real one. &lt;/p&gt;

&lt;p&gt;Is a reverse proxy just a doorman👮🖐️? Nah, it's a guardian🎠⚔️, I would say!&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Keep the original IP with X-Forwarded-For
&lt;/h2&gt;

&lt;p&gt;From the app's point of view, every request comes from the reverse proxy. If nothing is done, the access log shows the same IP for everyone, and you can't block an IP or look into abuse. So the reverse proxy adds X-Forwarded-For:  when it forwards the request, and the app reads that header for logs and security checks. A client can fake this header, so only trust values added by a reverse proxy you trust.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Examples of reverse proxies
&lt;/h2&gt;

&lt;p&gt;Reverse proxies come as dedicated software and as cloud services. These are the common ones.&lt;br&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkl71mwlao0uohduels7b.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkl71mwlao0uohduels7b.png" alt="List of Reverse proxies" width="799" height="381"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How this connects to AI🤖
&lt;/h2&gt;

&lt;p&gt;Apps that use AI have the same kind of doorman in front. It is usually called an &lt;strong&gt;AI gateway&lt;/strong&gt;🤖⚔️(or you can say an &lt;strong&gt;LLM proxy&lt;/strong&gt;): a reverse proxy placed in front of LLM APIs. It is still a reverse proxy underneath, but it does more than pass requests along. It &lt;strong&gt;also handles authentication, usage limits, and switching between models&lt;/strong&gt;, so people call it a gateway, like an entrance that manages everything coming in.&lt;br&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmt5x58nrbt70apskzfyg.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmt5x58nrbt70apskzfyg.png" alt="How this connects to AI?" width="800" height="727"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;They are slow.&lt;/strong&gt; A normal page comes back in milliseconds. An LLM answer can take many seconds, because the model writes it a little at a time. If every part of the system waits for the whole answer, the user stares at a blank screen, and connections that sit idle too long get cut by timeouts. &lt;strong&gt;A reverse proxy set up for this passes each piece along as it arrives (streaming), so the text starts showing right away.&lt;/strong&gt; It can also allow longer timeouts for these requests, and retry or switch to another model when one provider fails.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;They cost money.&lt;/strong&gt; A normal page costs almost nothing per visit. An LLM call is billed by the amount of text (tokens), so one buggy loop or one abusive user can run up a large bill. &lt;strong&gt;Because the reverse proxy sits at the front door, it can limit how many requests each user or app may send, answer repeated questions from a cache&lt;/strong&gt; instead of calling the API again, and record the usage and cost for each user or app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;A leaked API key can do real damage.&lt;/strong&gt; An API key works like a credit card number: anyone who has it can spend your money. If every app, script, and teammate holds the real key, one leak in a repository or a log exposes it. &lt;strong&gt;With a gateway, only the gateway holds the real key.&lt;/strong&gt; Apps get an internal key instead, and you can limit, replace, or cancel that internal key on its own without touching the real one.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For instance, here is what the key problem looks like with three apps.&lt;br&gt;
&lt;strong&gt;Without a gateway.&lt;/strong&gt; The three apps each call OpenAI directly. The real key lives in three places.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&lt;span class="c1"&gt;# App A .env
&lt;/span&gt;&lt;span class="na"&gt;OPENAI_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sk&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nb"&gt;real&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;
&lt;span class="c1"&gt;# App B .env
&lt;/span&gt;&lt;span class="na"&gt;OPENAI_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sk&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nb"&gt;real&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;
&lt;span class="c1"&gt;# App C .env
&lt;/span&gt;&lt;span class="na"&gt;OPENAI_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sk&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nb"&gt;real&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;With a gateway.&lt;/strong&gt; The apps call the gateway instead. The gateway checks the internal key, swaps in the real key, and forwards the request to OpenAI. The real key lives in one place.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Apps A, B, C .env (a different value for each app)
&lt;/span&gt;&lt;span class="na"&gt;GATEWAY_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;internal&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;

&lt;span class="c1"&gt;# Gateway .env
&lt;/span&gt;&lt;span class="na"&gt;OPENAI_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sk&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nb"&gt;real&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Either way, the key sits in an environment variable. What changes is how many places hold the real key. To replace it, you update one place instead of three. &lt;strong&gt;If App B leaks its key, you cancel only App B's internal key, and the real key stays safe.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The app talks only to the gateway, and the gateway forwards the request to each company's LLM API. The app doesn't have to hold the API key. Rate limits, caching, usage and cost records, and switching between models all happen in one place. LiteLLM Proxy and Cloudflare AI Gateway are examples of this kind of gateway.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;A reverse proxy is easy to forget about, but it is the guardian that holds up a website's safety, speed, and day-to-day running. In the example.com flow we followed, the reverse proxy did all of this by itself:&lt;br&gt;
• Showed the certificate and encrypted the connection with HTTPS (TLS termination)&lt;br&gt;
• Looked at the domain and path and sent the request to the right container&lt;br&gt;
• Passed the original client IP to the app&lt;br&gt;
• Kept the certificate renewed automatically&lt;/p&gt;

&lt;p&gt;Because all of this sits in one place, the app can focus on its own logic. Thanks, our guardian🎠⚔️!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>security</category>
      <category>network</category>
    </item>
    <item>
      <title>Why Next.js Navigation Doesn’t Work as Expected</title>
      <dc:creator>Atena / Full stack developer</dc:creator>
      <pubDate>Thu, 12 Feb 2026 21:44:01 +0000</pubDate>
      <link>https://dev.to/atena/why-nextjs-navigation-doesnt-work-as-expected-h3c</link>
      <guid>https://dev.to/atena/why-nextjs-navigation-doesnt-work-as-expected-h3c</guid>
      <description>&lt;p&gt;We ran into an issue where clicking a menu item sometimes did not navigate to the expected page.&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%2Firzc3cwhfdnlm5e78qe4.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%2Firzc3cwhfdnlm5e78qe4.png" alt=" " width="800" height="59"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The URL in the address bar would change correctly, but the content on the screen would not update. If we kept clicking the menu, navigation would occasionally work.&lt;strong&gt;The issue did not appear in local development, but only in the production environment&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It took some time to figure out the cause and solution, I would like to share what we learned.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reason
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Next.js Sends an RSC Request When a &lt;code&gt;&amp;lt;Link&amp;gt;&lt;/code&gt; Is Clicked
&lt;/h3&gt;

&lt;p&gt;In the App Router, clicking a &lt;code&gt;&amp;lt;Link&amp;gt;&lt;/code&gt; component triggers a client-side navigation instead of a full page reload. To render the next page, Next.js sends an internal request related to React Server Components (RSC) to fetch the server-rendered data required for the transition.&lt;/p&gt;

&lt;p&gt;It allows the page to update without reloading the entire document.&lt;/p&gt;

&lt;h3&gt;
  
  
  What We Found in the Network Tab
&lt;/h3&gt;

&lt;p&gt;While inspecting the Network tab during navigation, we noticed the following response headers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x-middleware-rewrite: /rate-limit-error?retryAfter=1&amp;amp;_rsc=xxxx
x-nextjs-rewritten-path: /rate-limit-error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;x-middleware-rewrite&lt;/code&gt;:&lt;br&gt;
The middleware rewrote the internal RSC request to the &lt;code&gt;rate-limit error&lt;/code&gt; route.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;x-nextjs-rewritten-path&lt;/code&gt;:&lt;br&gt;
Next.js ultimately processed the request as &lt;code&gt;/rate-limit-error&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This means that when an internal RSC request was triggered, the middleware rewrote it to the rate-limit error route, and Next.js ultimately processed the request as /rate-limit-error.&lt;/p&gt;
&lt;h3&gt;
  
  
  Flow of the Issue
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;The user clicks a &lt;code&gt;&amp;lt;Link&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Next.js sends an internal RSC request to fetch data for the next page.&lt;/li&gt;
&lt;li&gt;The rate-limiting middleware incorrectly applies rate limiting to this internal request.&lt;/li&gt;
&lt;li&gt;The middleware rewrites the request to /rate-limit-error.&lt;/li&gt;
&lt;li&gt;The browser URL remains correct, but the fetched content comes from a different route.&lt;/li&gt;
&lt;li&gt;This mismatch causes the page to appear broken or not update as expected.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This mismatch causes the page to appear broken or not update as expected.&lt;/p&gt;
&lt;h3&gt;
  
  
  Let's fix
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Before
&lt;/h4&gt;

&lt;p&gt;Our rate-limiting middleware was too broad and could apply to internal Next.js requests. As a result, RSC requests triggered by  navigation were sometimes rate-limited and rewritten to &lt;code&gt;/rate-limit-error&lt;/code&gt;, causing the URL and rendered content to mismatch.&lt;br&gt;
Before (problem)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Rate limit applied too broadly
const shouldRateLimit = true; ←too broad

// Incomplete RSC detection
const hasRscParam = requestUrl.includes('_rsc=');
const hasRscHeader = request.headers.get('rsc') === '1';
const isRSCRequest = hasRscParam || hasRscHeader;

// Internal requests were not excluded
if (shouldRateLimit &amp;amp;&amp;amp; isRateLimited) {
  return NextResponse.rewrite(
    new URL('/rate-limit-error', request.url)
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Problem:&lt;br&gt;
Internal RSC requests triggered by  navigation could be rate-limited and rewritten.&lt;/p&gt;
&lt;h4&gt;
  
  
  After
&lt;/h4&gt;

&lt;p&gt;We restricted rate limiting to API routes and non-GET requests only, and explicitly excluded internal Next.js requests (RSC/router requests). This prevented the middleware from rewriting navigation-related requests and restored stable client-side routing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Rate limit only APIs and non-GET requests
const isApiRoute = pathname.startsWith('/api/');
const isNonGetRequest = request.method !== 'GET';
const shouldRateLimit = isApiRoute || isNonGetRequest;

// Accurate RSC detection
const hasRscParam = requestUrl.includes('_rsc=');
const hasRscHeader = request.headers.get('rsc') === '1';
const hasRscAccept =
  request.headers.get('accept')?.includes('text/x-component');
const isRSCRequest = hasRscParam || hasRscHeader || hasRscAccept;

// Exclude internal navigation requests
if (shouldRateLimit &amp;amp;&amp;amp; !isRSCRequest &amp;amp;&amp;amp; isRateLimited) {
  return NextResponse.rewrite(
    new URL('/rate-limit-error', request.url)
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Exclude internal RSC requests from rate limiting and apply rate limits only to API and non-GET requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  To avoid similar issues in the future
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Apply rate limiting only to API routes and non-GET requests.&lt;/li&gt;
&lt;li&gt;Explicitly exclude internal Next.js requests such as RSC and router-related requests from middleware logic.&lt;/li&gt;
&lt;li&gt;Be cautious when using rewrites in middleware, especially with client-side navigation.&lt;/li&gt;
&lt;li&gt;When navigation behaves inconsistently, inspect the Network tab and response headers to check for unexpected rewrites.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keeping these points in mind helps ensure stable navigation and avoids hard-to-debug issues in production.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>projectcollegecms</category>
    </item>
    <item>
      <title>Boosting LCP: Next.js Performance with next/dynamic</title>
      <dc:creator>Atena / Full stack developer</dc:creator>
      <pubDate>Thu, 12 Feb 2026 21:37:37 +0000</pubDate>
      <link>https://dev.to/atena/boosting-lcp-nextjs-performance-with-nextdynamic-3100</link>
      <guid>https://dev.to/atena/boosting-lcp-nextjs-performance-with-nextdynamic-3100</guid>
      <description>&lt;p&gt;Every frontend engineer knows the pain. Your team keeps requesting you to add new features to the website, and suddenly your LCP score takes a nose dive.&lt;/p&gt;

&lt;p&gt;This is exactly where &lt;code&gt;next/dynamic&lt;/code&gt; saves the day. I’ve used this method to rescue performance scores. &lt;/p&gt;

&lt;h2&gt;
  
  
  1. What is &lt;code&gt;next/dynamic&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;It’s a tool for &lt;strong&gt;Lazy Loading your React components&lt;/strong&gt;. When you do a standard import like import Header from &lt;code&gt;'./Header'&lt;/code&gt;, that component gets bundled into the main JavaScript file. This means the browser has to download, parse, and execute that code before the user can really interact with the page. This kills your LCP score. &lt;br&gt;
&lt;code&gt;next/dynamic&lt;/code&gt; lets you tell the bundler: "Don't load this yet. Wait until we actually need it." It splits the code into a separate "chunks" file.&lt;br&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%2F80g2ip0wn04yzbnsbhqa.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%2F80g2ip0wn04yzbnsbhqa.png" alt="Explanation of next/dynamic" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Two Strategies for Using It
&lt;/h2&gt;

&lt;p&gt;There are two main ways I use &lt;code&gt;next/dynamic&lt;/code&gt;, depending on what I'm trying to fix.&lt;/p&gt;
&lt;h3&gt;
  
  
  Strategy 1: Optimizing for Timing (Fixing LCP)
&lt;/h3&gt;

&lt;p&gt;This is for things the user doesn't see immediately, like heavy components or a section way down the page. By lazy loading these, you let the browser focus 100% of its energy on rendering the Hero section. This makes the perceived load time much faster.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const HeavyComponent = dynamic(() =&amp;gt; import('../components/Heavy'),
 {
  loading: () =&amp;gt; &amp;lt;p&amp;gt;Loading...&amp;lt;/p&amp;gt;,
 })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Strategy 2: Optimizing for Location (Server vs. Browser)
&lt;/h3&gt;

&lt;p&gt;Sometimes, you have code that simply cannot run on the server. Maybe it uses window, document, or a library. By using the &lt;code&gt;ssr: false&lt;/code&gt; option, you force the component to be rendered entirely on the client side.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const MapComponent = dynamic(() =&amp;gt; import('../components/Map'),
 {
  ssr: false, // Skip the server entirely!
 })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. &lt;code&gt;next/dynamic&lt;/code&gt; vs. &lt;code&gt;'use client'&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This is where I got confused. If I import a component with &lt;code&gt;ssr: true&lt;/code&gt;, but that component has &lt;code&gt;'use client'&lt;/code&gt;, does that make it CSR?&lt;/p&gt;

&lt;p&gt;The answer is No. It is still SSR first.&lt;br&gt;
To clear up this confusion, we need to correct our mental model.&lt;/p&gt;

&lt;h3&gt;
  
  
  Method vs. Declaration
&lt;/h3&gt;

&lt;p&gt;We must distinguish between the Method and the Declaration. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SSR/CSR is a Method. It describes when and where the rendering happens.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'use client'&lt;/code&gt; is a Declaration. It signals what features (like hooks or event listeners) are being used.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It can be confusing that adding &lt;code&gt;'use client'&lt;/code&gt; opts out of SSR. This is wrong. In the Next.js App Router, even if you mark a component with &lt;code&gt;'use client'&lt;/code&gt;, it is still rendered on the server initially.&lt;/p&gt;

&lt;p&gt;Then how does the  &lt;code&gt;'use client'&lt;/code&gt; work with SSR/ CSR?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;SSR with &lt;code&gt;'use client'&lt;/code&gt;&lt;br&gt;
The server pre-renders the HTML Shell (the tags like &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; inside the server box).  The &lt;code&gt;'use client'&lt;/code&gt; acts as &lt;strong&gt;Hydration&lt;/strong&gt;  to make the existing button interactive after it arrives in the browser. The HTML is born on the Server. The user sees the content immediately.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSR with &lt;code&gt;'use client'&lt;/code&gt;&lt;br&gt;
The server skips rendering and sends an Empty Shell. The server skips rendering and sends an Empty Shell. Here, the JavaScript bundle must build the entire UI from scratch inside the &lt;strong&gt;Browser&lt;/strong&gt;. The user waits for the JS to load before seeing any content.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&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%2Fbc7a54h8lrnu393bdvui.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%2Fbc7a54h8lrnu393bdvui.png" alt="Explanation of CSR vs SSR with use cleint" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Performance is all about control.You need to know what is rendering, where it's rendering, and when.&lt;/p&gt;

&lt;p&gt;Want to improve LCP?&lt;br&gt;
→ Use next/dynamic to split up your heavy JS bundles.&lt;/p&gt;

&lt;p&gt;Fixing a "window is undefined" error?&lt;br&gt;
→ Use ssr: false to skip the server execution entirely.&lt;/p&gt;

&lt;p&gt;Need a button to click?&lt;br&gt;
→ Use 'use client' to add interactivity (while keeping SSR).&lt;/p&gt;

&lt;p&gt;But remember, with&lt;code&gt;'use client'&lt;/code&gt;, the HTML is still born on the server. Learning this distinction is the key to building Next.js apps that feel instant.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>performance</category>
      <category>lcp</category>
      <category>projectcollegecms</category>
    </item>
  </channel>
</rss>
