<?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: Marius Ibsen</title>
    <description>The latest articles on DEV Community by Marius Ibsen (@lobunto).</description>
    <link>https://dev.to/lobunto</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%2F121498%2F08b64812-737f-478d-b003-1090f5b38ca1.png</url>
      <title>DEV Community: Marius Ibsen</title>
      <link>https://dev.to/lobunto</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lobunto"/>
    <language>en</language>
    <item>
      <title>Git reflog: Restore Version Control History</title>
      <dc:creator>Marius Ibsen</dc:creator>
      <pubDate>Fri, 02 Sep 2022 11:33:42 +0000</pubDate>
      <link>https://dev.to/lobunto/git-reflog-restore-version-control-history-ke1</link>
      <guid>https://dev.to/lobunto/git-reflog-restore-version-control-history-ke1</guid>
      <description>&lt;p&gt;Did you know we can use Git reference logs to restore Git commit history(?) Often we developers experience challenges when working with Git. We can accidentally force-push commits to the remote main branch, complete a rebase that went bad, delete a branch we wanted to keep or hard reset to the wrong commit.&lt;/p&gt;

&lt;p&gt;In this post, we will look at &lt;code&gt;git reflog&lt;/code&gt; and &lt;code&gt;git reset&lt;/code&gt;. We will review some common scenarios on restoring local commits, restoring a deleted branch, and reverting force-pushed changes due to a rebase.&lt;/p&gt;

&lt;h2&gt;
  
  
  Git reflog
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://medium.com/r/?url=https%3A%2F%2Fgit-scm.com%2Fdocs%2Fgit-reflog" rel="noopener noreferrer"&gt;git reflog&lt;/a&gt; is a tool that can help us recover almost anything - at least everything we have committed. The tool keeps track of commits that have been created but also discarded ones in a log called the reference log. The reference log is kept on our local computer under the &lt;code&gt;.git&lt;/code&gt; directory in a local repository. It contains a list of commits that &lt;code&gt;HEAD&lt;/code&gt; has pointed to and keeps track of the entire history of a commit. Besides the reference log for branches, we have a separate reference log for stash.&lt;/p&gt;

&lt;p&gt;(Records of the history on a branch will expire after 30 days by default. We can change the expiration days, by running &lt;code&gt;git reflog —expire&lt;/code&gt; in our terminal, if we want to keep the history for a longer time.)&lt;/p&gt;

&lt;p&gt;It's important to know that &lt;em&gt;reference logs&lt;/em&gt; do not track in the remote repository, like pushes, fetches and clones; it is purely local and current to the working environment. Below is two screencaps, the first from Github Codespaces and the second from a local filesystem that initially created all the commits of the main branch in the &lt;em&gt;same&lt;/em&gt; repository:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Github Codespaces&lt;/strong&gt;:&lt;br&gt;
&lt;a href="https://media.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%2Fae4iplwe9uk8a8v575ra.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fae4iplwe9uk8a8v575ra.png" alt="Reference log from a workspace in Github Codespaces"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Local computer&lt;/strong&gt;:&lt;br&gt;
&lt;a href="https://media.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%2F0szc19whz79i1abqcwqf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F0szc19whz79i1abqcwqf.png" alt="Reference log from local computer where the commits were initially created"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Git log vs reflog
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://git-scm.com/docs/git-log" rel="noopener noreferrer"&gt;git log&lt;/a&gt; is a command that shows a list of commits related to a branch. &lt;code&gt;git reflog&lt;/code&gt; is similar to &lt;code&gt;git log&lt;/code&gt; but shows a list of snapshots and times when &lt;code&gt;HEAD&lt;/code&gt; was changed. reference logs  also reference other types such as &lt;em&gt;stash&lt;/em&gt;, &lt;em&gt;branches&lt;/em&gt;, &lt;em&gt;rebase&lt;/em&gt;, &lt;em&gt;merge&lt;/em&gt; and &lt;em&gt;tags&lt;/em&gt;. A reference is known as &lt;em&gt;refs&lt;/em&gt;, and the syntax for accessing these is &lt;code&gt;name@{qualifier}&lt;/code&gt;. Running &lt;code&gt;git reflog&lt;/code&gt; is the most basic use case and essentially the equivalent of writing &lt;code&gt;git reflog show HEAD&lt;/code&gt;. The output will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; git reflog

47efaa2 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;0&lt;span class="o"&gt;}&lt;/span&gt;: commit: refactor: remove post schema
f243f12 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;1&lt;span class="o"&gt;}&lt;/span&gt;: commit: refactor: change author fields
4783ba0 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;2&lt;span class="o"&gt;}&lt;/span&gt;: commit: chore: add .env to gitignore
a19d142 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;3&lt;span class="o"&gt;}&lt;/span&gt;: commit: chore: update readme
f5ade9a HEAD@&lt;span class="o"&gt;{&lt;/span&gt;4&lt;span class="o"&gt;}&lt;/span&gt;: commit: chore: update yarn.lock
854c08f HEAD@&lt;span class="o"&gt;{&lt;/span&gt;5&lt;span class="o"&gt;}&lt;/span&gt;: commit &lt;span class="o"&gt;(&lt;/span&gt;initial&lt;span class="o"&gt;)&lt;/span&gt;: feat: bootstrap sanity studio
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Git reset
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://git-scm.com/docs/git-reset" rel="noopener noreferrer"&gt;git reset&lt;/a&gt; is a command we can use to move back to a previous commit, discarding or undoing previous changes. We can run &lt;code&gt;git reset --hard &amp;lt;commit_sha&amp;gt;&lt;/code&gt; to move our branch back in the commit history.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A hard reset&lt;/strong&gt; (&lt;code&gt;git reset --hard&lt;/code&gt;) will &lt;em&gt;completely destroy any changes&lt;/em&gt; and remove them from your local repository.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A soft reset&lt;/strong&gt; (&lt;code&gt;git reset --soft&lt;/code&gt;) will keep your changes, and stage them back automatically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A mixed reset&lt;/strong&gt; (&lt;code&gt;git reset --mixed&lt;/code&gt;) which is the default, will keep you changes but they will also become unstaged. Even tho it is flexible, you will have to stage the changes manually.&lt;/p&gt;

&lt;h2&gt;
  
  
  Restore local commits
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Scenario
&lt;/h3&gt;

&lt;p&gt;We have made some commits that haven’t been pushed to the remote repository yet. We do a &lt;code&gt;git reset —-hard &amp;lt;commit_sha&amp;gt;&lt;/code&gt; to a previous commit, and our local branch is set back to an earlier point and discarded all history after the chosen commit. We then run &lt;code&gt;git log&lt;/code&gt; and see that the commits are gone. We cannot pull the changes from the remote repository since we never synced the changes.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to restore local commits
&lt;/h3&gt;

&lt;p&gt;When running git reflog we can see that our changes still are tracked by the reference log; we even have a separate commit for the hard reset that we did earlier - take a look at commit &lt;code&gt;f243f12&lt;/code&gt; on &lt;code&gt;HEAD@{0}&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;f243f12 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;0&lt;span class="o"&gt;}&lt;/span&gt;: reset: moving to f243f12
eec6f27 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;1&lt;span class="o"&gt;}&lt;/span&gt;: commit: refactor: author should not have image
47efaa2 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;2&lt;span class="o"&gt;}&lt;/span&gt;: commit: refactor: remove post schema
f243f12 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;3&lt;span class="o"&gt;}&lt;/span&gt;: commit: refactor: change author fields
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this information, we can reset our branch back to the state we discarded by using one of the references in the reflog. We can move our branch to the selected commit by running &lt;code&gt;git reset --hard &amp;lt;commit_sha&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; f243f12
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; git reflog

f243f12 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;0&lt;span class="o"&gt;}&lt;/span&gt;: reset: moving to eec6f27
f243f12 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;1&lt;span class="o"&gt;}&lt;/span&gt;: reset: moving to f243f12
eec6f27 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;2&lt;span class="o"&gt;}&lt;/span&gt;: commit: refactor: author should not have image
47efaa2 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;3&lt;span class="o"&gt;}&lt;/span&gt;: commit: refactor: remove post schema
f243f12 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;4&lt;span class="o"&gt;}&lt;/span&gt;: commit: refactor: change author fields
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Restore a deleted branch
&lt;/h2&gt;

&lt;p&gt;We can recover deleted branches using SHA’s in the reference logs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scenario
&lt;/h3&gt;

&lt;p&gt;Not uncommonly, we might checkout a new branch in our local environment. We could have a branch called &lt;code&gt;chore/update-packages&lt;/code&gt; and commit a change that adds &lt;a href="https://day.js.org/" rel="noopener noreferrer"&gt;dayjs&lt;/a&gt; as a package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; chore/add-dayjs-package
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; yarn add dayjs
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; git add &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s1"&gt;'chore: add dayjs package'&lt;/span&gt;

5a75042 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;0&lt;span class="o"&gt;}&lt;/span&gt;: commit: chore: add dayjs package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At a later point, we checkout the &lt;em&gt;main&lt;/em&gt; branch and deletes the &lt;code&gt;chore/add-dayjs-package&lt;/code&gt; branch — maybe we did not need it anymore for some reason:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; git checkout main

47efaa2 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;0&lt;span class="o"&gt;}&lt;/span&gt;: moving from chore/add-dayjs-package to main

&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; git branch &lt;span class="nt"&gt;-D&lt;/span&gt; chore/add-dayjs-package

Deleted branch chore/add-dayjs-package &lt;span class="o"&gt;(&lt;/span&gt;was 5a75042&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will get a confirmation message that git deleted the branch. After a while, we discover that we could need the changes after all, so how do we get them back?&lt;/p&gt;

&lt;h3&gt;
  
  
  How to restore a deleted branch
&lt;/h3&gt;

&lt;p&gt;We can undo these changes with &lt;code&gt;git reflog&lt;/code&gt; and &lt;code&gt;git checkout&lt;/code&gt;. If we run &lt;code&gt;git reflog&lt;/code&gt; we won't see any references to the deleted branch. We could use the commit SHA provided in the delete message (&lt;code&gt;5a75042&lt;/code&gt;) to revert the latest commit on that branch. But if we have lost the message, we need to use the reference log. And if you named your commits well, it should be easy to find the missing commit take a look at commit &lt;code&gt;5a75042&lt;/code&gt; on &lt;code&gt;HEAD@{1}&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; git reflog

// deletion of a branch is not logged to the reference log
47efaa2 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;0&lt;span class="o"&gt;}&lt;/span&gt;: moving from chore/add-dayjs-package to main
5a75042 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;1&lt;span class="o"&gt;}&lt;/span&gt;: commit: chore: add dayjs package
47efaa2 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;2&lt;span class="o"&gt;}&lt;/span&gt;: moving from main to chore/add-dayjs-package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can now checkout the deleted commit SHA and create a new branch from that commit running &lt;code&gt;git checkout -b &amp;lt;branch_name&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; git checkout 5a75042
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; chore/add-dayjs-package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Revert force-pushed changes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Scenario
&lt;/h3&gt;

&lt;p&gt;We reset our branch using git reset --hard to an earlier commit and run git push - force to override any changes that we otherwise could pull from the remote repository. But at some point, we want those changes back.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; &amp;lt;commit_sha&amp;gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; git push &lt;span class="nt"&gt;--force&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How to revert force-pushed changes
&lt;/h3&gt;

&lt;p&gt;We can use git reflog and git reset to restore force-pushed changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; git reflog

f243f12 HEAD@&lt;span class="o"&gt;{&lt;/span&gt;0&lt;span class="o"&gt;}&lt;/span&gt;: reset: a19d142 to f243f12
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By reading the log we can see that the message on &lt;code&gt;HEAD@{0}&lt;/code&gt; is &lt;code&gt;reset: a19d142 to f243f12&lt;/code&gt;, which means that commit with hash &lt;code&gt;a19d142&lt;/code&gt; was force-pushed by &lt;code&gt;f243f12&lt;/code&gt;. That also gives us information about which commit we need to restore, the one with hash &lt;code&gt;a19d142&lt;/code&gt;. We can simply do the same procedure as initially to move back to the overriden commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; a19d142
git push &lt;span class="nt"&gt;--force&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, we force-push the new changes to the remote repository. Always be careful and check that you are on the correct branch before doing a force push. Especially to prevent that production code is not being affected or team member code is not being overwritten.&lt;/p&gt;

&lt;p&gt;Thanks for reading! (This article was &lt;a href="https://medium.com/dfind-consulting/restore-commit-history-with-git-reflog-67f7676e902f" rel="noopener noreferrer"&gt;originally posted on Medium&lt;/a&gt; )&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Code foh shizzle&lt;/em&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>versioncontrol</category>
      <category>productivity</category>
    </item>
    <item>
      <title>React Scroll Hook with Shadows</title>
      <dc:creator>Marius Ibsen</dc:creator>
      <pubDate>Fri, 06 May 2022 22:56:10 +0000</pubDate>
      <link>https://dev.to/lobunto/react-scroll-hook-with-shadows-1fd6</link>
      <guid>https://dev.to/lobunto/react-scroll-hook-with-shadows-1fd6</guid>
      <description>&lt;p&gt;Liquid syntax error: Unknown tag 'endraw'&lt;/p&gt;
</description>
    </item>
    <item>
      <title>3 Ways of Rendering on The Web</title>
      <dc:creator>Marius Ibsen</dc:creator>
      <pubDate>Thu, 29 Apr 2021 08:25:27 +0000</pubDate>
      <link>https://dev.to/lobunto/3-ways-of-rendering-on-the-web-5b6h</link>
      <guid>https://dev.to/lobunto/3-ways-of-rendering-on-the-web-5b6h</guid>
      <description>&lt;p&gt;Rendering a website can be done in several ways. A common challenge is when to choose which of the types.&lt;/p&gt;

&lt;p&gt;Exploring the options before starting a new project can prevent us from refactoring parts of our code or the entire tech stack. It depends on whether it is crucial to get a good ranking in Google. Or if the content should be more interactive, dynamic, and fade smoothly into the user's view. Or if performance and excellent user experience are more essential for your business goals.&lt;/p&gt;

&lt;p&gt;All websites have different needs and having some basic understanding of the rendering on the web will spare you money, time, and frustration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Concepts and terminology
&lt;/h2&gt;

&lt;p&gt;First, we will go through some basic technical concepts and terminology. Knowing a little about them will help us make even better decisions on our website's rendering options.&lt;/p&gt;

&lt;p&gt;These concepts we can divide into two categories: Performance and Rendering.&lt;/p&gt;

&lt;h3&gt;
  
  
  Performance
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hydration&lt;/strong&gt; is a technique where JavaScript converts static HTML (returned from the Server) into dynamic and interactive elements in the browser. Also generally referred to as client-side hydration or re-hydration. When hydrating, JavaScript (such as event handlers, listeners, etc.) is linked to the static HTML to make it interactive.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pre-rendering&lt;/strong&gt; is a technique where the HTML is rendered A Head of Time at build-time. Pre-rendering is essential for public pages that should get crawled and ranked by search engines. Server-side and Static-side applications use this technique.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Rendering
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;First Paint (FP)&lt;/strong&gt; is the first step during rendering after a user navigates to a page. It is the first pixel painted on the screen and in the browser window - everything in the browser window that is visually different from before navigation is processed in the First Paint.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;First Contentful Paint (FCP)&lt;/strong&gt; is the first time the browser renders something to the DOM, such as text, images, or SVG's. During this process, the browser will tell the user that "something is happening."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Time to Interactive (TTI)&lt;/strong&gt;. The browser has rendered the entire website content, at this point, and the user can interact with the elements on the page. That could be pressing a button or clicking in text fields that give some feedback to the user.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Client-Side Rendering (CSR)
&lt;/h2&gt;

&lt;p&gt;Client-side rendered websites do everything "on their own." Such as retrieve data from an API, manage logic, and routing between pages directly in the browser. Every page the visitor visits and its respective URL are being created dynamically.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We can think of rendering on the Client like package delivery, of three packages. Each package will come in a different order and at different times, but you don't know precisely when. You will get the first package, then the second, and at last the third.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Client-side applications typically have a fast FP and FCP. They use hydration which can cause a slow Time to Interactive because the browser needs to "boot up" the JavaScript code, rehydrate, and then load the HTML back into the browser window. The hydration process may vary in time depending on how much JavaScript your application contains.&lt;/p&gt;

&lt;p&gt;A slow TTI is not very good for Search Engine Optimization (SEO). Most Client-side applications that need their content crawled and optimized for SEO will have to implement pre-rendering to make it work properly.&lt;/p&gt;

&lt;p&gt;Client-side rendering is the default for JavaScript applications. Popular Frontend Frameworks like React, Angular, and Vue use this rendering type.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Gives the user quick feedback and a smooth user experience, e.g., a fast First Contentful Paint.&lt;/li&gt;
&lt;li&gt;Low server load because all the content is processed and rendered on the client/in the user's browser.&lt;/li&gt;
&lt;li&gt;Lower costs than a Server-side rendered application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;May cause poor user experience. Potentially, leave the user waiting for content until everything is fully loaded into the browser, resulting in the user leaving the site instead.&lt;/li&gt;
&lt;li&gt;Client-side applications make it hard for search engine robots to see the website content, which leads to no or poor indexing.&lt;/li&gt;
&lt;li&gt;JavaScript pages will not be visible if JavaScript is disabled in the users' browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Server-Side Rendering (SSR)
&lt;/h2&gt;

&lt;p&gt;Server-side rendering (SSR) happens On-demand, also called Just in Time (JIT). Every time the Client makes a request for a page, the Server generates HTML for that request. The HTML is then returned to the Client, wholly rendered, ready to be displayed.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We can think of rendering on the Server like package delivery, much like for Client-side rendering. Instead of getting the packages delivered at different times, you get all at the same time.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Server-side rendering is slower than Static-side rendering because the HTML is generated entirely on each request. But it's faster than a client-side rendered application when returning the entire result to the user.&lt;/p&gt;

&lt;p&gt;JavaScript frameworks like Vue and React use hydration to generate interactive code sent from the Server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Suitable for SEO-focused websites.&lt;/li&gt;
&lt;li&gt;Gives the user a great user experience by delivering all content on request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It may be expensive. Require setup and managing of servers or server code besides frontend code.&lt;/li&gt;
&lt;li&gt;If the Server is down, the website is also down.&lt;/li&gt;
&lt;li&gt;It may require a backend/full stack developer in addition to a frontend developer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Static-Side Rendering
&lt;/h1&gt;

&lt;p&gt;Static rendering happens at build-time. Every page is compiled and rendered as static HTML files Ahead Of Time (AOT). Files generated AOT means that we will produce an HTML file with a separate URL for each file. What is excellent about static websites is that they can be uploaded to a CDN and easily be moved to another source when needed without much work.&lt;/p&gt;

&lt;p&gt;We can think of rendering an application statically, much like on the server, just that it is incredibly fast. The packages don't need to be packed beforehand; they're just shipped to you at once.&lt;/p&gt;

&lt;p&gt;Statically rendered websites have some significant advantages. They are fast, have better reliability, and improved SEO. Websites generated statically have fast FP, FCP, and TTI.&lt;/p&gt;

&lt;p&gt;A few months ago, I wrote an article about what benefits you can draw from having Static Generated Websites. You are welcome to read it: &lt;a href="https://medium.com/r/?url=https%3A%2F%2Fmarius-ibsen.medium.com%2Fbenefits-of-static-websites-5fb187d1ffe6"&gt;Benefits of Static Websites&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Perfect for SEO-focused websites.&lt;/li&gt;
&lt;li&gt;Reliable, excellent performance, secure, and scalable&lt;/li&gt;
&lt;li&gt;Low costs; it can "live" on a Content Delivery Network (CDN)&lt;/li&gt;
&lt;li&gt;Easy to move between hosting providers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You are dependent on deploying the entire website in case of changes - like pushing news articles or products for an e-commerce shop.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Let's wrap up
&lt;/h1&gt;

&lt;p&gt;If you ask yourself, "When should one be critical to the choice of rendering type?" this is just relevant when a website contains JavaScript.&lt;/p&gt;

&lt;p&gt;CSR may provide a faster response (FCP) to the user. It is more interactive and perfect when content needs to be updated without contacting the Server. On the other hand, suppose you build a website with full JavaScript. In that case, some JavaScript frameworks like React, Vue, or Angular will, in most cases, only render an empty HTML page. Search engine crawlers will see these sites as completely blank until fully rendered.&lt;/p&gt;

&lt;p&gt;Many JavaScript frameworks that have become popular in the past years have built-in Static Site Generation (SSG) and Server-side rendering, such as GatsbyJS and NextJS, supporting both SSR and SSG.&lt;/p&gt;

&lt;p&gt;SSR and SSG are better for SEO. Both can display page content faster. They give a better user experience, and search engine robots will have it easier to rank your pages. Suppose you have a static website that consists only of HTML. In that case, you do not need to pay attention or worry about SEO optimization or excessive server load at all.&lt;/p&gt;

&lt;p&gt;On the latest project I've been working on, we've used a combination of client and static rendering for a couple of years. Doing so is essential because the customer I work for has a website that is both a news page and contains pages where users can see their customer relationship behind some secured pages.&lt;/p&gt;

&lt;p&gt;Going entirely for just server-side or just client-side, I would not recommend if you are in the same situation as I described above. Know when to use the different rendering types, and you will make fantastic websites that also give the user a great user experience.&lt;/p&gt;

&lt;p&gt;Thank you for reading! &lt;em&gt;Code for shizzle&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;(This article was &lt;a href="https://medium.com/grensesnittet/3-ways-of-rendering-on-the-web-4363864c859e"&gt;originally posted&lt;/a&gt; on Medium )&lt;/p&gt;

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