<?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>Forem: Shohanur Rahman Sabber</title>
    <description>The latest articles on Forem by Shohanur Rahman Sabber (@sabberrahman).</description>
    <link>https://forem.com/sabberrahman</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%2F2042417%2Fd3a80770-b236-469d-9824-61e6158f9d54.jpeg</url>
      <title>Forem: Shohanur Rahman Sabber</title>
      <link>https://forem.com/sabberrahman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sabberrahman"/>
    <language>en</language>
    <item>
      <title>When to use SSR and SSG in Next.js</title>
      <dc:creator>Shohanur Rahman Sabber</dc:creator>
      <pubDate>Fri, 03 Jan 2025 15:37:32 +0000</pubDate>
      <link>https://forem.com/sabberrahman/when-to-use-ssr-and-ssg-in-nextjs-2b73</link>
      <guid>https://forem.com/sabberrahman/when-to-use-ssr-and-ssg-in-nextjs-2b73</guid>
      <description>&lt;p&gt;&lt;strong&gt;SSR (Server-Side Rendering):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Runs on every request to the server.&lt;/em&gt;&lt;br&gt;
Each time a user visits the page, the server fetches the data, renders the HTML, and sends it to the client.&lt;br&gt;
This ensures that the content is always fresh, but it can be slower due to the overhead of server-side processing.&lt;/p&gt;

&lt;p&gt;Example Timeline for SSR:&lt;/p&gt;

&lt;p&gt;Request 1: User A visits → Server fetches data, generates page dynamically, and responds.&lt;/p&gt;

&lt;p&gt;Request 2: User B visits → Server fetches data again, generates page dynamically, and responds.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getServerSideProps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`https://api.example.com/data`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="c1"&gt;// Will be passed to the page component as props&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Page&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;Content&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Page&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;SSG (Static Site Generation):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Runs at build time (when you execute next build).&lt;/em&gt;&lt;br&gt;
The HTML and data are pre-rendered and saved as static files. These files are served directly to users, making it super fast.&lt;/p&gt;

&lt;p&gt;Optional: If you use revalidate, Next.js will rebuild the page in the background after the specified time interval, ensuring updated content is available.&lt;br&gt;
Example Timeline for SSG with revalidate: 60:&lt;/p&gt;

&lt;p&gt;Build time: The page is pre-rendered with the data available at build time.&lt;/p&gt;

&lt;p&gt;Request 1 :(after build): User A visits → Static HTML is served.&lt;/p&gt;

&lt;p&gt;Background regeneration (after 60 seconds): Next.js fetches fresh data and regenerates the page.&lt;/p&gt;

&lt;p&gt;Request 2 : (after regeneration): User B visits → The updated static HTML is served.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getStaticProps&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.example.com/posts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
      &lt;span class="nx"&gt;posts&lt;/span&gt; 
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="c1"&gt;// Optional: Regenerate the page at most once every 60 seconds&lt;/span&gt;
    &lt;span class="na"&gt;revalidate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;BlogPage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;))}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;SSR:&lt;/u&gt; Fetches fresh data and generates the page on every request.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;SSG:&lt;/u&gt; Pre-renders the page once at build time (or during scheduled revalidate intervals), and serves the same pre-built page to all users until it's regenerated.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Use SSR when:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You need real-time, up-to-date content (e.g., dashboards, user-specific data).&lt;br&gt;
The content changes frequently and cannot be cached effectively.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Use SSG when:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The content doesn't change often (e.g., blog posts, marketing pages).&lt;br&gt;
Speed and performance are critical.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Mastering Git: How to Delete Local, Merged, and Remote Branches</title>
      <dc:creator>Shohanur Rahman Sabber</dc:creator>
      <pubDate>Thu, 12 Sep 2024 14:32:45 +0000</pubDate>
      <link>https://forem.com/sabberrahman/mastering-git-how-to-delete-local-merged-and-remote-branches-34e3</link>
      <guid>https://forem.com/sabberrahman/mastering-git-how-to-delete-local-merged-and-remote-branches-34e3</guid>
      <description>&lt;p&gt;In the world of software development, effective version control is crucial for ensuring smooth collaboration and project management. Git is one of the most widely used version control systems, and knowing how to handle branches efficiently can save time and prevent mistakes.&lt;/p&gt;

&lt;p&gt;In this article, we'll explore how to manage local, merged, and remote Git branches, focusing on the commands that help streamline your workflow.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Deleting a Local Git Branch&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When working on a project, it's common to create local branches for specific features, bug fixes, or experiments. &lt;/p&gt;

&lt;p&gt;However, once a branch has served its purpose, keeping it around can clutter your repository. Here's how to delete a local Git branch:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git branch -d &amp;lt;branch-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command deletes the specified branch, but only if it has been fully merged into another branch (e.g., main). If Git detects that the branch has unmerged changes, it will prevent deletion to avoid losing work.&lt;/p&gt;

&lt;p&gt;If you are sure you want to delete an unmerged branch, you can use the -D flag:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git branch -D &amp;lt;branch-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This force-deletes the branch, even if it contains unmerged changes. Use this option carefully.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Deleting a Merged Git Branch&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After merging a feature branch into the main codebase, you may want to delete the branch locally to keep your working environment clean. Use the same command as above:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git branch -d &amp;lt;branch-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This ensures that the merged branch is removed from your local environment, allowing you to focus on active tasks without unnecessary clutter.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Deleting a Remote Git Branch&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A remote branch is a branch that exists on a shared remote repository, such as GitHub or GitLab. While local branches only exist on your machine, remote branches are available for anyone who has access to the repository.&lt;/p&gt;

&lt;p&gt;To delete a remote branch, the following command is used:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git push origin --delete &amp;lt;branch-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command instructs Git to delete the specified branch from the remote repository (origin). This is especially helpful for cleaning up old feature branches that are no longer needed after merging them into the main branch.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is a Remote Git Branch?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A remote branch refers to a branch that is hosted on a remote repository. Remote branches are often used for collaboration in teams, allowing everyone to push and pull changes to and from the repository.&lt;/p&gt;

&lt;p&gt;When you clone a Git repository, you're also downloading references to all the branches from the remote repository. You can view both your local and remote branches using this command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git branch -a&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This lists:&lt;br&gt;
Local branches (e.g., main, feature-branch)&lt;br&gt;
Remote branches (e.g., remotes/origin/main, remotes/origin/feature-branch)&lt;/p&gt;

&lt;p&gt;Understanding how to manage both local and remote branches is crucial for maintaining a clean, organized workflow, especially when working with larger teams.&lt;/p&gt;

&lt;p&gt;By mastering these Git commands, you'll improve not only your own productivity but also your team's efficiency when managing project branches.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
