{"componentChunkName":"component---src-templates-blog-list-template-js","path":"/120","result":{"data":{"allMarkdownRemark":{"edges":[{"node":{"excerpt":"Rendering is an essential procedure a programmer has to manage in frontend development. In React, the render() method is the only required…","fields":{"slug":"/engineering/understanding-react-rendering/"},"html":"<p>Rendering is an essential procedure a programmer has to manage in frontend development. In React, <a href=\"https://reactjs.org/docs/react-component.html#render\">the render() method is the only required method in a class component</a> and is responsible for describing the view to be rendered to the browser window. Coupled with the clever way React operates around its virtual DOM concept, there are certain subtleties in how this method works. Understanding them will greatly benefit any aspiring React developer. </p>\n<p>Throughout this writing, I will reference <a href=\"https://codepen.io/n-nguyen/pen/WNwYrRG\">this codepen</a> for a demonstration of discussed behaviors.</p>\n<h3 id=\"1-strongcoderendercodestrong-101\" style=\"position:relative;\"><a href=\"#1-strongcoderendercodestrong-101\" aria-label=\"1 strongcoderendercodestrong 101 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>1. <strong><code>render()</code></strong> 101</h3>\n<p>First of all, <strong><code>render()</code></strong> is not user callable. It is part of the <a href=\"https://reactjs.org/docs/state-and-lifecycle.html\">React component lifecycle</a>. Generally, it gets called by React at various app stages when the React component instantiates for the first time, or when there is a new update to the component state. Render does not take any arguments and returns a <strong><code>JSX.Element</code></strong> which contains the view hierarchy of the current component. This view hierarchy will later be translated into HTML and displayed in the browser window.</p>\n<p>As mentioned before, <strong><code>render()</code></strong> is not user callable as it is an event that happens in the component’s lifecycle. With that said, if it is absolutely necessary to render the view manually, you can instead call the built-in class method <strong><code><a href=\"https://reactjs.org/docs/react-component.html#forceupdate\">forceUpdate()</a></code></strong>. Keep in mind that this is considered an <strong>anti-pattern</strong>. If you were designing sensible React components, its state and props changes should naturally control the render process, and you should never feel the need to make a manual call.</p>\n<p>Within the lifecycle, these are the scenarios where render is called: </p>\n<ul>\n<li>After the React component is first instantiated, following the <strong><code>constructor()</code></strong> call.</li>\n<li>After an update to the component’s props</li>\n<li>After a <strong><code>setState()</code></strong> call</li>\n</ul>\n<p>If you have the <a href=\"https://codepen.io/n-nguyen/pen/WNwYrRG\">Codepen</a> opened at this point, before anything is rendered you will see 2 alert messages from the browser: <code>\"render() is called in Parent component!\"</code>, and <code>\"render() is called in Child component!\"</code>. These messages are invoked from the corresponding <strong><code>render()</code></strong> methods of the example's parent and child component. They serve to introduce the first case of <strong><code>render()</code></strong> invocation: when the component is first instantiated.</p>\n<p>Once the set of alerts is dismissed, a very simple UI will render:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 16.923076923076923%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAADCAYAAACTWi8uAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAhUlEQVQI13WOywrDIBRE8/9/1kBqK3URXzULXdgsVfABUxW6axbD4TJw7izn+QFjL0ghcBwHROdba0gpse8c3nuklNBaQ631MqMPIWBxzmFdb6CUghDS+QR5kP6EYdvukzFGlFKQc5n8lyGdQmvtXGWMgf4t43xSaQWl1OzHPcQ558sM6RcTFOCXs69UKAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Example UI\"\n        title=\"Example UI\"\n        src=\"/static/ef87ae44122c627360f0cf876950ce20/e5715/image1.png\"\n        srcset=\"/static/ef87ae44122c627360f0cf876950ce20/a6d36/image1.png 650w,\n/static/ef87ae44122c627360f0cf876950ce20/e5715/image1.png 768w,\n/static/ef87ae44122c627360f0cf876950ce20/62a6a/image1.png 1122w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>The dotted border line distinguishes between elements that belong to the Child component of the example (inside the dotted line) versus the Parent component.</p>\n<ul>\n<li>Clicking button 1 will update the <strong><code>childElementText</code></strong> state of the Parent component, which in turns updates the <strong><code>text</code></strong> prop of the Child component, triggering a render in both Parent and Child.</li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk11\">onChildPropChange</span><span class=\"mtk1\"> = () </span><span class=\"mtk4\">=&gt;</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk11\">setState</span><span class=\"mtk1\">({</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">childElementText:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;I am the child element! I am updated following a prop change.&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    })</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  }</span></span></code></pre>\n<ul>\n<li>Clicking button 2 will update the <strong><code>helloWorldMessage</code></strong> state within Child component, triggering a render following a state change.</li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk11\">onTextChange</span><span class=\"mtk1\"> = () </span><span class=\"mtk4\">=&gt;</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk11\">setState</span><span class=\"mtk1\">({</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">helloWorldMessage:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;Hello React! (state change after setState call)&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    })</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  }</span></span></code></pre>\n<p>A visual and interactive reference to the React lifecycle can be found <a href=\"https://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/\">here</a>.</p>\n<p>It is worth noting that following a props update or <strong><code>setState()</code></strong>, the method <strong><code>shouldComponentUpdate()</code></strong> is invoked to determine whether <strong><code>render()</code></strong> should be called. By default, this method always returns <strong><code>true</code></strong>. But it can be overloaded to implement custom logic. It is the actual way to define custom render behavior in each React component.</p>\n<p>The <strong><code>shouldComponentUpdate()</code></strong> provides you with nextProp and nextState as arguments, which allows you to compare the current state and props of the component. For example, this code block will invoke <strong><code>render()</code></strong> only when the <strong><code>text</code></strong> prop changes:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk11\">shouldComponentUpdate</span><span class=\"mtk1\">(</span><span class=\"mtk12\">nextProps</span><span class=\"mtk1\">: </span><span class=\"mtk12\">NewComponentProps</span><span class=\"mtk1\">, </span><span class=\"mtk12\">nextState</span><span class=\"mtk1\">: </span><span class=\"mtk12\">NewComponentState</span><span class=\"mtk1\">) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">if</span><span class=\"mtk1\"> (</span><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk12\">props</span><span class=\"mtk1\">.</span><span class=\"mtk12\">text</span><span class=\"mtk1\"> !== </span><span class=\"mtk12\">nextProps</span><span class=\"mtk1\">.</span><span class=\"mtk12\">text</span><span class=\"mtk1\">) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> </span><span class=\"mtk4\">true</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    } </span><span class=\"mtk15\">else</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> </span><span class=\"mtk4\">false</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    }</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  }</span></span></code></pre>\n<p>The characteristics and behaviors mentioned above made it imperative that <strong><code>render()</code></strong> is a pure function. That means inside <strong><code>render()</code></strong>, you should not make an update to the component's states or props (no setState() call nor Redux state update). This makes sense because an update to the component will then trigger a new <strong><code>render()</code></strong> call, which can potentially lock you into an infinite render loop.</p>\n<p>In terms of return value: <strong><code>render()</code></strong> returns a single JSX element, as mentioned above. This comes with certain implications:</p>\n<ul>\n<li>If you need to return a collection of sibling elements, you need to wrap them all in a parent <strong><code>&#x3C;div></code></strong>, or a <strong><code>&#x3C;React.Fragment></code></strong>. It is worth noting that once rendered, <strong><code>&#x3C;React.Fragment></code></strong> will vanish from the DOM structure. It is only meant to be a wrapper component and does not appear in the final DOM in the browser. This makes it a more sensible choice over a <strong><code>&#x3C;div></code></strong> wrapping to avoid nesting div’s.</li>\n<li>JSX is immutable. The returned JSX element is a constant that represents the state of the DOM to be rendered. Therefore, when thinking about how to write a <strong><code>render()</code></strong> method, it is helpful to think about how the entire UI will look like at a moment in time, instead of thinking about how a certain element updates over time. <a href=\"https://reactjs.org/docs/rendering-elements.html#react-only-updates-whats-necessary\">“Thinking about how the UI should look at any given moment, rather than how to change it over time, eliminates a whole class of bugs.”</a></li>\n</ul>\n<h3 id=\"2-notes-on-reconciliation-and-the-strongcodekeycodestrong-prop\" style=\"position:relative;\"><a href=\"#2-notes-on-reconciliation-and-the-strongcodekeycodestrong-prop\" aria-label=\"2 notes on reconciliation and the strongcodekeycodestrong prop permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>2. Notes on reconciliation, and the <strong><code>key</code></strong> prop</h3>\n<p>The <strong><code>render()</code></strong> method in each React component then feeds into what is called the Reconciliation Algorithm. This is the primary algorithm that dictates how React renders the real DOM in your browser based on a <strong>virtual DOM </strong>maintained internally by React. To intelligently determine what needs to be rendered on every call, React compares the current state of the virtual DOM and the real one and only makes changes to the physical DOM where it recognizes that the UI has been updated.</p>\n<p>While not every single detail is known about React’s reconciliation algorithm, the characteristics detailed in the <a href=\"https://reactjs.org/docs/reconciliation.html\">official documentation</a> are enough for us to start phasing out certain suboptimal rendering patterns, thus writing a more robust <strong><code>render()</code></strong> method.</p>\n<ul>\n<li>On a UI update: As the DOM tree is parsed top to bottom, if a mismatch of elements is detected, React will <a href=\"https://reactjs.org/docs/reconciliation.html#elements-of-different-types\">tear down and rebuild the entire subtree</a> starting from that element. If the subtree is complex, this operation can be quite costly. Therefore, if a new element were to be introduced to the DOM tree, it should be appended as the last element in that level if there are no specific requirements of where it should be placed.</li>\n</ul>\n<p>For instance, given this DOM subtree:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"html\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">div</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk1\"> </span><span class=\"mtk12\">key</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;li-1&quot;</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 1</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk1\"> </span><span class=\"mtk12\">key</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;li-2&quot;</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 2</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk1\"> </span><span class=\"mtk12\">key</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;li-3&quot;</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 3</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">div</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>If a <strong><code>&#x3C;NewComponent></code></strong> is then added to the top of the list:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"html\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">div</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  &lt;!-- previously </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 1</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\"> - element is detached and </span><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">NewComponent</span><span class=\"mtk1\"> </span><span class=\"mtk17\">/&gt;</span><span class=\"mtk1\"> instantiated --&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">NewComponent</span><span class=\"mtk1\"> </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  &lt;!-- previously </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 2</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\"> - content will be updated to &quot;list item 1&quot;  --&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 1</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  &lt;!-- previously </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 3</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\"> - content will be updated to &quot;list item 2&quot;  --&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 2</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  &lt;!-- new </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 3</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\"> is element created  --&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 3</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">div</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>If instead <strong><code>&#x3C;NewComponent></code></strong> is added to the bottom: </p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"html\" data-index=\"5\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">div</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  &lt;!-- previously </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 1</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\"> - no change --&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 1</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  &lt;!-- previously </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 2</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\"> - no change --&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 2</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  &lt;!-- previously </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 3</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\"> - no change --&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 3</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  &lt;!-- new instance of </span><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">NewComponent</span><span class=\"mtk1\"> </span><span class=\"mtk17\">/&gt;</span><span class=\"mtk1\"> is added --&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">NewComponent</span><span class=\"mtk1\"> </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">div</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p> In the example above, appending <strong><code>&#x3C;NewComponent></code></strong> to the end of the list will result in 1 new instantiation, versus 1 instantiation, 3 updates and 1 tear down. In a larger application scale, this will prove to be a significant performance difference in the long run.</p>\n<ul>\n<li>\n<p>If you have ever tried to use the <strong><code>map()</code></strong> method to iterate over an array to render a list of elements, it is likely that you have seen React complaining about a missing <strong><code>key</code></strong> prop to each rendered list item. So what does the <strong><code>key</code></strong> actually do?</p>\n<p>A <strong><code>key</code></strong> is React’s way to recognize elements in the DOM tree, comes reconciliation time. When React is parsing all children of an element, it can leverage keys to match elements that were present from the last update. That allows you to shuffle the order of child elements without interfering with the algorithm. As long as the key matches between updates, React will preserve the element configuration.</p>\n</li>\n</ul>\n<p>Coming back to the example above, let’s add keys to all the existing list items:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"html\" data-index=\"6\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">div</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk1\"> </span><span class=\"mtk12\">key</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;li-1&quot;</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 1</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk1\"> </span><span class=\"mtk12\">key</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;li-2&quot;</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 2</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk1\"> </span><span class=\"mtk12\">key</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;li-3&quot;</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 3</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">div</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>In this case, if we were to add an extra “list item 4” at the top of the list, it would not come with the same performance penalty:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"html\" data-index=\"7\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">div</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  &lt;!-- new item - </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\"> is instantiated --&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk1\"> </span><span class=\"mtk12\">key</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;li-4&quot;</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 4</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  &lt;!-- matched with the old &quot;li-1&quot; key - element stays unchanged between renders --&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk1\"> </span><span class=\"mtk12\">key</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;li-1&quot;</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 1</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  &lt;!-- matched with the old &quot;li-2&quot; key - element stays unchanged between renders --&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk1\"> </span><span class=\"mtk12\">key</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;li-2&quot;</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 2</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  &lt;!-- matched with the old &quot;li-3&quot; key - element stays unchanged between renders --&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">span</span><span class=\"mtk1\"> </span><span class=\"mtk12\">key</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;li-3&quot;</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">list item 3</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">span</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">div</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>In case a subtree is generated using a <strong><code>map()</code></strong> or other iterative methods, React requires that keys are provided with the element. However, even in case a DOM subtree is manually added, keys should be provided on subtrees that have complex behaviors regarding conditional rendering.</p>\n<h3 id=\"3-parting-words\" style=\"position:relative;\"><a href=\"#3-parting-words\" aria-label=\"3 parting words permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>3. Parting words</h3>\n<p>React is a clever framework that offers performance through its rendering scheme, so it follows that, as developers, we should leverage it appropriately to help build performant applications. With that said, it is not a miracle device that optimizes out inefficiencies from the developer’s end, but a tool to be utilized. Understanding the <strong><code>render()</code></strong> nd its implication to the reconciliation algorithm is the first step to make sure we are leveraging the framework instead of working against it. It is also one of the first steps to mastering React.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n  .dark-default-dark .mtk1 { color: #D4D4D4; }\n  .dark-default-dark .mtk11 { color: #DCDCAA; }\n  .dark-default-dark .mtk4 { color: #569CD6; }\n  .dark-default-dark .mtk12 { color: #9CDCFE; }\n  .dark-default-dark .mtk8 { color: #CE9178; }\n  .dark-default-dark .mtk15 { color: #C586C0; }\n  .dark-default-dark .mtk17 { color: #808080; }\n  .dark-default-dark .mtk10 { color: #4EC9B0; }\n</style>","frontmatter":{"date":"September 23, 2020","updated_date":null,"description":"Optimized rendering in the frontend is a crucial procedure. Let's learn how to optimize React rendering process.","title":"How to Render React with optimization","tags":["Node.js","React"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/a22b36cdcd9eba841d06147e84b867f9/ee604/index.png","srcSet":"/static/a22b36cdcd9eba841d06147e84b867f9/69585/index.png 200w,\n/static/a22b36cdcd9eba841d06147e84b867f9/497c6/index.png 400w,\n/static/a22b36cdcd9eba841d06147e84b867f9/ee604/index.png 800w,\n/static/a22b36cdcd9eba841d06147e84b867f9/f3583/index.png 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Nathan Nguyen","github":"nathannguyenn","avatar":null}}}},{"node":{"excerpt":"What are Ajax and XHR? Ajax stands for Asynchronous Javascript and  XML. Ajax is a programming technique that allows us to create dynamic…","fields":{"slug":"/engineering/ajax-and-xhr-using-plain-javascript/"},"html":"<h2 id=\"what-are-ajax-and-xhr\" style=\"position:relative;\"><a href=\"#what-are-ajax-and-xhr\" aria-label=\"what are ajax and xhr permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What are Ajax and XHR?</h2>\n<p><strong>Ajax</strong> stands for Asynchronous Javascript and  XML. Ajax is a programming technique that allows us to create dynamic, complex, and asynchronous web applications. Ajax allows us to send and receive data from the webserver asynchronously without interfering with the current state or behavior of the web page or application.</p>\n<p><strong>XHR</strong> is the XMLHttpRequest Object which interacts with the server. Ajax technique in the nutshell leverages the XHR request to send and receive data from the webserver. This object is provided by the browser’s javascript environment. It transfers the data between the web browser and server.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 512px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 48.04687499999999%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsTAAALEwEAmpwYAAAC7UlEQVQoz41Qa0hTARj9rtnLXj/K53TpNOdjvpqlNgyknAvJajlokYZvTBB7EJP52Ms93LzbnZMMH4gRGmVWKrqp273bvXths0grpYyI6G8Q/Qq6XaHf0YGPjw8O55zvAPxFMjON05+R2slNqBl7lV4/udFYP/GuqnY0GC0dfgnSkVWk3BaA/4ZkeBW5eD8E523+hGvja1+bx1dMdQ9e49Lxt5uHpH27EptHQGQhIbZp+N9CbH0I4rsJJLfXt/P80Gs4a/GeEd0LbVRNbkGDZmR/5QBpG+0fDL9pfgypKiKc1elEjioIyFQ6ELbCvSOybQriugiEo8TDZAodI9gTRKI7cTjSRQJP6wG+jijKN/nXuT3MbfDV5Bn9H7kaT0mGloQohhMpcwC72xXGCEK8wg2Fw5+Qw3IckpQ43Fb2AcR2uiCm3c6PlS9Vh0n7d7PkDslRpTvAaZ8pSNfgH471UHSm2rmQeHeaEyNfaoi5O8tiyRchRT7Hj+tYvpFj24AjskUuu2Ox5dSdoT1A0zRwVO5XyWqSTu12KI6p8M0kNUVnqJYncjqeFTDvhdqulu/mKAn9NidJSQymMemLlC84qWr3j0QFbkhWudcz1M7Rgz1rABkaojJLT73J0xEGno6yC7QLFfk63NGKPTqQpnGnMzWssGWzbJ7e++G41iXj6amP3C47hzGEYvUMP8vgo3N0nuWDxi1g0gGc7PO7ilHvzxITgRehgd+M2C2B0TN4aTAA2Xoy+6TRG+QbSJUA9dMlJnxOgPpopmNN6cAKnDD5rQLU+72oz7fFGOaeNhIAQiv1rdzsuiDunUkSWampUjMRKMW8X8owcr7MSvmFZvcToYUMnsM8Gon+aRyzO4QYGRIZHU1Cq/eX2DSXJcJIS5mFfC++g+6FGsvzOCFGgRi1Qyv6MKLOPBXVjE1HXrG5SqS25cI249i+65YZ1vY7l812ABsN1eizBIl5IaUFm44WY06guxGkGptPqdA/j/gDRF1M2+UHgNQAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Ajax Call\"\n        title=\"Ajax Call\"\n        src=\"/static/0b3f8f49bac659dd799f1b3751067747/01e7c/ajax.png\"\n        srcset=\"/static/0b3f8f49bac659dd799f1b3751067747/01e7c/ajax.png 512w\"\n        sizes=\"(max-width: 512px) 100vw, 512px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<h4 id=\"key-technologies-for-incorporating-ajax--\" style=\"position:relative;\"><a href=\"#key-technologies-for-incorporating-ajax--\" aria-label=\"key technologies for incorporating ajax   permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Key technologies for incorporating AJAX -</h4>\n<ul>\n<li>HTML DOM(document object model)</li>\n<li>JSON/XML</li>\n<li>XMLHttpRequest</li>\n<li>Javascript</li>\n</ul>\n<h3 id=\"why-ajax---benefits-of-ajax\" style=\"position:relative;\"><a href=\"#why-ajax---benefits-of-ajax\" aria-label=\"why ajax   benefits of ajax permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Why AJAX-  benefits of AJAX</h3>\n<p>Dynamic content modification of web page: Using Ajax reloading of a web page is not required. The content of a web page can be modified dynamically by calling the XHR request in the background and changing the content using DOM Modification.</p>\n<h3 id=\"sending-an-xhr-request\" style=\"position:relative;\"><a href=\"#sending-an-xhr-request\" aria-label=\"sending an xhr request permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Sending an XHR request</h3>\n<p>To send and receive data from the server and implement the Ajax simple steps are explained below:</p>\n<ul>\n<li>Create a XMLHttpRequest object. </li>\n<li>Send the request to retrieve data from the server.</li>\n<li>Receive the response and display information to the end-user.</li>\n</ul>\n<h4 id=\"create-a-xmlhttprequest-object-\" style=\"position:relative;\"><a href=\"#create-a-xmlhttprequest-object-\" aria-label=\"create a xmlhttprequest object  permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Create a XMLHttpRequest object :</h4>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">xhrobj</span><span class=\"mtk1\"> = </span><span class=\"mtk4\">new</span><span class=\"mtk1\"> </span><span class=\"mtk10\">XMLHttpRequest</span><span class=\"mtk1\">();</span></span></code></pre>\n<h4 id=\"send-the-request-\" style=\"position:relative;\"><a href=\"#send-the-request-\" aria-label=\"send the request  permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Send the request :</h4>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk12\">xhrobj</span><span class=\"mtk1\">.</span><span class=\"mtk11\">open</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;GET&#39;</span><span class=\"mtk1\">,</span><span class=\"mtk8\">&#39;example.com/get&#39;</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">xhrobj</span><span class=\"mtk1\">.</span><span class=\"mtk11\">send</span><span class=\"mtk1\">();</span></span></code></pre>\n<table>\n<thead>\n<tr>\n<th></th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>open(method, url[, async[, user[, password]]])</td>\n<td>It initializes the request.</td>\n</tr>\n<tr>\n<td><code>method</code></td>\n<td>request type such as GET,POST etc</td>\n</tr>\n<tr>\n<td><code>url</code></td>\n<td>Request URL</td>\n</tr>\n<tr>\n<td><code>Async</code></td>\n<td>true or false</td>\n</tr>\n<tr>\n<td><code>user</code></td>\n<td>Username for basic authentication</td>\n</tr>\n<tr>\n<td><code>password</code></td>\n<td>Password for basic authentication</td>\n</tr>\n<tr>\n<td>send(body)</td>\n<td>It sends the request to the server body : it is optional to send body of data with request.</td>\n</tr>\n</tbody>\n</table>\n<p>In case of sending POST request :</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">xhrobj</span><span class=\"mtk1\">.</span><span class=\"mtk11\">open</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;POST&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&#39;example.com/post&#39;</span><span class=\"mtk1\">, </span><span class=\"mtk4\">true</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">xhrobj</span><span class=\"mtk1\">.</span><span class=\"mtk11\">setRequestHeader</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Content-type&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;application/x-www-form-urlencoded&quot;</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">xhrobj</span><span class=\"mtk1\">.</span><span class=\"mtk11\">send</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;username=john&quot;</span><span class=\"mtk1\">);</span></span></code></pre>\n<table>\n<thead>\n<tr>\n<th></th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>setRequestHeader(header,value)</code></td>\n<td>It sets the header for the HTTP request.</td>\n</tr>\n<tr>\n<td><code>header</code></td>\n<td>name of header parameter</td>\n</tr>\n<tr>\n<td><code>Value</code></td>\n<td>value of the parameter</td>\n</tr>\n</tbody>\n</table>\n<h4 id=\"receiving-the-response-\" style=\"position:relative;\"><a href=\"#receiving-the-response-\" aria-label=\"receiving the response  permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Receiving the response :</h4>\n<p>On completion of the request, the server sends the response to the request.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk12\">xhrobj</span><span class=\"mtk1\">.</span><span class=\"mtk11\">onreadystatechange</span><span class=\"mtk1\"> = </span><span class=\"mtk4\">function</span><span class=\"mtk1\"> () {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk15\">if</span><span class=\"mtk1\"> (</span><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk12\">readyState</span><span class=\"mtk1\"> == </span><span class=\"mtk7\">4</span><span class=\"mtk1\"> && </span><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk12\">status</span><span class=\"mtk1\"> == </span><span class=\"mtk7\">200</span><span class=\"mtk1\">) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk11\">getElementById</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;response&quot;</span><span class=\"mtk1\">).</span><span class=\"mtk12\">innerHTML</span><span class=\"mtk1\"> = </span><span class=\"mtk12\">xhrobj</span><span class=\"mtk1\">.</span><span class=\"mtk12\">responseText</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  }</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span></code></pre>\n<table>\n<thead>\n<tr>\n<th></th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>onreadystatechange = callback()</code></td>\n<td>It is a EventHandler called when the readyState attribute changes.</td>\n</tr>\n<tr>\n<td><code>readyState</code> attribute</td>\n<td>It is an attribute that returns the current state of XMLHttpRequest object</td>\n</tr>\n<tr>\n<td><code>status</code> attribute</td>\n<td>It is an attribute that returns the status code to the HTTP XHR request.</td>\n</tr>\n<tr>\n<td><code>responseText</code> attribute</td>\n<td>It is an attribute that returns the DOMstring response as the text.</td>\n</tr>\n</tbody>\n</table>\n<h3 id=\"conclusion\" style=\"position:relative;\"><a href=\"#conclusion\" aria-label=\"conclusion permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Conclusion</h3>\n<p>Implementing the Ajax technique by using the XHR in javascript instead of going with using other javascript library functions like jQuery.ajax has advantages as well. For example, it gives you the freedom to embed your application or script with other applications or platform even if the particular library is not used by other applications. Thus it also helps in code reusability.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n  .dark-default-dark .mtk4 { color: #569CD6; }\n  .dark-default-dark .mtk1 { color: #D4D4D4; }\n  .dark-default-dark .mtk12 { color: #9CDCFE; }\n  .dark-default-dark .mtk10 { color: #4EC9B0; }\n  .dark-default-dark .mtk11 { color: #DCDCAA; }\n  .dark-default-dark .mtk8 { color: #CE9178; }\n  .dark-default-dark .mtk15 { color: #C586C0; }\n  .dark-default-dark .mtk7 { color: #B5CEA8; }\n</style>","frontmatter":{"date":"September 22, 2020","updated_date":null,"description":"Learn the concept of AJAX and XHR in JavaScript, the benefits of AJAX, and how easy it is to implement the AJAX into our web application.","title":"Ajax and XHR using plain JS","tags":["XHR","JavaScript","AJAX"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.7699115044247788,"src":"/static/d7c8bd46314d7f9ac3b770feb90916f5/ee604/index.png","srcSet":"/static/d7c8bd46314d7f9ac3b770feb90916f5/69585/index.png 200w,\n/static/d7c8bd46314d7f9ac3b770feb90916f5/497c6/index.png 400w,\n/static/d7c8bd46314d7f9ac3b770feb90916f5/ee604/index.png 800w,\n/static/d7c8bd46314d7f9ac3b770feb90916f5/f3583/index.png 1200w,\n/static/d7c8bd46314d7f9ac3b770feb90916f5/e4d72/index.png 1280w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Apeksha Gupta","github":"ApekshaAgarwal","avatar":null}}}},{"node":{"excerpt":"Before You Get Started This tutorial assumes you have: A basic understanding of Go Language Latest GoLang version installed on your system…","fields":{"slug":"/engineering/mongodb-as-datasource-in-golang/"},"html":"<h2 id=\"before-you-get-started\" style=\"position:relative;\"><a href=\"#before-you-get-started\" aria-label=\"before you get started permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Before You Get Started</h2>\n<p>This tutorial assumes you have:</p>\n<ul>\n<li>A basic understanding of Go Language</li>\n<li>Latest GoLang version installed on your system</li>\n<li>Latest MongoDB version installed on your system</li>\n</ul>\n<p>In this tutorial, we will use the official <strong><a href=\"https://github.com/mongodb/mongo-go-driver/\">MongoDB Go Driver</a></strong> to manage our MongoDB database. In the due process, we will write a program to learn how to install the MongoDB Go Driver and perform CRUD operations with it.</p>\n<h2 id=\"installation\" style=\"position:relative;\"><a href=\"#installation\" aria-label=\"installation permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Installation</h2>\n<p>First in an empty folder run the below command</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">go mod init gomongo</span></code></pre>\n<p><code>go mod init</code> creates a new go.mod file and automatically imports dependencies when you will run go program. Then create the file main.go and write the below code, We will explain what this code will do in a min.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"go\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">package</span><span class=\"mtk1\"> main</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">import</span><span class=\"mtk1\"> (</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk8\">&quot;context&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk8\">&quot;fmt&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk8\">&quot;log&quot;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk8\">&quot;go.mongodb.org/mongo-driver/bson&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk8\">&quot;go.mongodb.org/mongo-driver/mongo&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk8\">&quot;go.mongodb.org/mongo-driver/mongo/options&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">// Book - We will be using this Book type to perform crud operations</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">type</span><span class=\"mtk1\"> </span><span class=\"mtk10\">Book</span><span class=\"mtk1\"> </span><span class=\"mtk4\">struct</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  Title     </span><span class=\"mtk10\">string</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  Author    </span><span class=\"mtk10\">string</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  ISBN      </span><span class=\"mtk10\">string</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  Publisher </span><span class=\"mtk10\">string</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  Copies     </span><span class=\"mtk10\">int</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">func</span><span class=\"mtk1\"> </span><span class=\"mtk11\">main</span><span class=\"mtk1\">() {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk3\">// Set client options</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">clientOptions</span><span class=\"mtk1\"> := options.</span><span class=\"mtk11\">Client</span><span class=\"mtk1\">().</span><span class=\"mtk11\">ApplyURI</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;mongodb://localhost:27017&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk3\">// Connect to MongoDB</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">client</span><span class=\"mtk1\">, </span><span class=\"mtk12\">err</span><span class=\"mtk1\"> := mongo.</span><span class=\"mtk11\">Connect</span><span class=\"mtk1\">(context.</span><span class=\"mtk11\">TODO</span><span class=\"mtk1\">(), clientOptions)</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk15\">if</span><span class=\"mtk1\"> err != </span><span class=\"mtk4\">nil</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    log.</span><span class=\"mtk11\">Fatal</span><span class=\"mtk1\">(err)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  }</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk3\">// Check the connection</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">err</span><span class=\"mtk1\"> = client.</span><span class=\"mtk11\">Ping</span><span class=\"mtk1\">(context.</span><span class=\"mtk11\">TODO</span><span class=\"mtk1\">(), </span><span class=\"mtk4\">nil</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk15\">if</span><span class=\"mtk1\"> err != </span><span class=\"mtk4\">nil</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    log.</span><span class=\"mtk11\">Fatal</span><span class=\"mtk1\">(err)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  }</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  fmt.</span><span class=\"mtk11\">Println</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Connected to MongoDB!&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">booksCollection</span><span class=\"mtk1\"> := client.</span><span class=\"mtk11\">Database</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;testdb&quot;</span><span class=\"mtk1\">).</span><span class=\"mtk11\">Collection</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;books&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span></code></pre>\n<p>In the above code, we have imported the bson, mongo, and mongo/options packages of mongo-driver and defined a <code>Book</code> type which will be used in this tutorial</p>\n<p>In the main function first, we created clientOptions with MongoDB URL and credentials and pass it to <code>mongo.Connect</code> function, Once connected we can check our connection by <code>client.Ping</code> function.</p>\n<p>The following code will use <code>booksCollection</code> variable to query the <code>books</code> collection from testdb.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"go\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk12\">booksCollection</span><span class=\"mtk1\"> := client.</span><span class=\"mtk11\">Database</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;testdb&quot;</span><span class=\"mtk1\">).</span><span class=\"mtk11\">Collection</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;books&quot;</span><span class=\"mtk1\">)</span></span></code></pre>\n<h2 id=\"insert-documents\" style=\"position:relative;\"><a href=\"#insert-documents\" aria-label=\"insert documents permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Insert Documents</h2>\n<p>First Let's create a Book struct to insert into the collection, in below code we are using <code>collection.InsertOne</code> function to insert a single document in the collection</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"go\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk3\">// Insert One document</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">book1</span><span class=\"mtk1\"> := Book{</span><span class=\"mtk8\">&quot;Animal Farm&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;George Orwell&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;0451526341&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;Signet Classics&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk7\">100</span><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">insertResult</span><span class=\"mtk1\">, </span><span class=\"mtk12\">err</span><span class=\"mtk1\"> := booksCollection.</span><span class=\"mtk11\">InsertOne</span><span class=\"mtk1\">(context.</span><span class=\"mtk11\">TODO</span><span class=\"mtk1\">(), book1)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> err != </span><span class=\"mtk4\">nil</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    log.</span><span class=\"mtk11\">Fatal</span><span class=\"mtk1\">(err)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">fmt.</span><span class=\"mtk11\">Println</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Inserted a single document: &quot;</span><span class=\"mtk1\">, insertResult.InsertedID)</span></span></code></pre>\n<p>To insert multiple documents at once we need to create a slice of <code>Book</code> object and pass it to <code>collection.InsertMany</code></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"go\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk3\">// Insert multiple documents</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">book2</span><span class=\"mtk1\"> := Book{</span><span class=\"mtk8\">&quot;Super Freakonomics&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;Steven D. Levitt&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;0062312871&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;HARPER COLLINS USA&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk7\">100</span><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">book3</span><span class=\"mtk1\"> := Book{</span><span class=\"mtk8\">&quot;The Alchemist&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;Paulo Coelho&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;0062315005&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;HarperOne&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk7\">100</span><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">multipleBooks</span><span class=\"mtk1\"> := []</span><span class=\"mtk4\">interface</span><span class=\"mtk1\">{}{book2, book3}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">insertManyResult</span><span class=\"mtk1\">, </span><span class=\"mtk12\">err</span><span class=\"mtk1\"> := booksCollection.</span><span class=\"mtk11\">InsertMany</span><span class=\"mtk1\">(context.</span><span class=\"mtk11\">TODO</span><span class=\"mtk1\">(), multipleBooks)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> err != </span><span class=\"mtk4\">nil</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    log.</span><span class=\"mtk11\">Fatal</span><span class=\"mtk1\">(err)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">fmt.</span><span class=\"mtk11\">Println</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Inserted multiple documents: &quot;</span><span class=\"mtk1\">, insertManyResult.InsertedIDs)</span></span></code></pre>\n<h2 id=\"update-documents\" style=\"position:relative;\"><a href=\"#update-documents\" aria-label=\"update documents permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Update Documents</h2>\n<p>We can update a single document by function  <code>collection.UpdateOne</code>. It requires a filter document to match documents in the collection and an updated document to describe the update operation. You can build these using bson.D types. The below code will match the book with <em>ISBN</em> <em>0451526341</em> and increment the copies field by <em>10</em></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"go\" data-index=\"5\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk3\">//Update one document</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">filter</span><span class=\"mtk1\"> := bson.D{{</span><span class=\"mtk8\">&quot;isbn&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;0451526341&quot;</span><span class=\"mtk1\">}}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">update</span><span class=\"mtk1\"> := bson.D{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    {</span><span class=\"mtk8\">&quot;$inc&quot;</span><span class=\"mtk1\">, bson.D{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        {</span><span class=\"mtk8\">&quot;copies&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk7\">10</span><span class=\"mtk1\">},</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    }},</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">updateResult</span><span class=\"mtk1\">, </span><span class=\"mtk12\">err</span><span class=\"mtk1\"> := booksCollection.</span><span class=\"mtk11\">UpdateOne</span><span class=\"mtk1\">(context.</span><span class=\"mtk11\">TODO</span><span class=\"mtk1\">(), filter, update)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> err != </span><span class=\"mtk4\">nil</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    log.</span><span class=\"mtk11\">Fatal</span><span class=\"mtk1\">(err)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">fmt.</span><span class=\"mtk11\">Printf</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Matched %v documents and updated %v documents.</span><span class=\"mtk6\">\\n</span><span class=\"mtk8\">&quot;</span><span class=\"mtk1\">, updateResult.MatchedCount, updateResult.ModifiedCount)</span></span></code></pre>\n<blockquote>\n<p>You can also update more than one documents at once in a single collection by function <code>collection.UpdateMany</code>, In it, we need to pass filter document and update document same as <code>collection.UpdateOne</code></p>\n</blockquote>\n<h2 id=\"find-documents\" style=\"position:relative;\"><a href=\"#find-documents\" aria-label=\"find documents permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Find Documents</h2>\n<p>To find a single document, we can use function <code>collection.FindOne()</code>, we will pass a filter document and decode the result in the <code>Book</code> type variable</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"go\" data-index=\"6\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk3\">// A variable in which result will be decoded</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">result</span><span class=\"mtk1\"> Book</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">err</span><span class=\"mtk1\"> = booksCollection.</span><span class=\"mtk11\">FindOne</span><span class=\"mtk1\">(context.</span><span class=\"mtk11\">TODO</span><span class=\"mtk1\">(), filter).</span><span class=\"mtk11\">Decode</span><span class=\"mtk1\">(&result)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> err != </span><span class=\"mtk4\">nil</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    log.</span><span class=\"mtk11\">Fatal</span><span class=\"mtk1\">(err)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">fmt.</span><span class=\"mtk11\">Printf</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Found a single document: %+v</span><span class=\"mtk6\">\\n</span><span class=\"mtk8\">&quot;</span><span class=\"mtk1\">, result)</span></span></code></pre>\n<p>To find multiple documents, we use function <code>collection.Find()</code>. This method returns a Cursor, It provides a stream of documents on which we can iterate or we can get all the docs by function <code>cursor.All()</code> in a slice of <code>Book</code> type. </p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"go\" data-index=\"7\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk12\">cursor</span><span class=\"mtk1\">, </span><span class=\"mtk12\">err</span><span class=\"mtk1\"> := booksCollection.</span><span class=\"mtk11\">Find</span><span class=\"mtk1\">(context.</span><span class=\"mtk11\">TODO</span><span class=\"mtk1\">(), bson.D{{}})</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> err != </span><span class=\"mtk4\">nil</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  log.</span><span class=\"mtk11\">Fatal</span><span class=\"mtk1\">(err)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">books</span><span class=\"mtk1\"> []Book</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> </span><span class=\"mtk12\">err</span><span class=\"mtk1\"> = cursor.</span><span class=\"mtk11\">All</span><span class=\"mtk1\">(context.</span><span class=\"mtk11\">TODO</span><span class=\"mtk1\">(), &books); err != </span><span class=\"mtk4\">nil</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  log.</span><span class=\"mtk11\">Fatal</span><span class=\"mtk1\">(err)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">fmt.</span><span class=\"mtk11\">Printf</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Found multiple documents: %+v</span><span class=\"mtk6\">\\n</span><span class=\"mtk8\">&quot;</span><span class=\"mtk1\">, books)</span></span></code></pre>\n<h2 id=\"delete-documents\" style=\"position:relative;\"><a href=\"#delete-documents\" aria-label=\"delete documents permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Delete Documents</h2>\n<p>We can delete documents from a collection using functions <code>collection.DeleteOne()</code> or <code>collection.DeleteMany()</code>. Here you pass bson.D{{}} as the filter argument, which will match all documents in the collection.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"go\" data-index=\"8\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk12\">deleteCollection</span><span class=\"mtk1\">, </span><span class=\"mtk12\">err</span><span class=\"mtk1\"> := booksCollection.</span><span class=\"mtk11\">DeleteMany</span><span class=\"mtk1\">(context.</span><span class=\"mtk11\">TODO</span><span class=\"mtk1\">(), bson.D{{}})</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> err != </span><span class=\"mtk4\">nil</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    log.</span><span class=\"mtk11\">Fatal</span><span class=\"mtk1\">(err)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">fmt.</span><span class=\"mtk11\">Printf</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Deleted %v documents in the books collection</span><span class=\"mtk6\">\\n</span><span class=\"mtk8\">&quot;</span><span class=\"mtk1\">, deleteCollection.DeletedCount)</span></span></code></pre>\n<blockquote>\n<p>Entire collection can be dropped using the collection.Drop() function, it will remove all documents and metadata, such as indexes from the collection</p>\n</blockquote>\n<p>Once you have done all the operation, don't forget to close the MongoDB connection</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"go\" data-index=\"9\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk12\">err</span><span class=\"mtk1\"> = client.</span><span class=\"mtk11\">Disconnect</span><span class=\"mtk1\">(context.</span><span class=\"mtk11\">TODO</span><span class=\"mtk1\">())</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> err != </span><span class=\"mtk4\">nil</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    log.</span><span class=\"mtk11\">Fatal</span><span class=\"mtk1\">(err)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">fmt.</span><span class=\"mtk11\">Println</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Connection to MongoDB closed.&quot;</span><span class=\"mtk1\">)</span></span></code></pre>\n<p>Now you can easily use MongoDB as Datasource in your go application, You can found the complete code used in this tutorial on our <a href=\"https://github.com/LoginRadius/engineering-blog-samples/tree/master/GoLang/MongoDriverForGolang\">Github Repo</a></p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n  .dark-default-dark .mtk4 { color: #569CD6; }\n  .dark-default-dark .mtk1 { color: #D4D4D4; }\n  .dark-default-dark .mtk8 { color: #CE9178; }\n  .dark-default-dark .mtk3 { color: #6A9955; }\n  .dark-default-dark .mtk10 { color: #4EC9B0; }\n  .dark-default-dark .mtk11 { color: #DCDCAA; }\n  .dark-default-dark .mtk12 { color: #9CDCFE; }\n  .dark-default-dark .mtk15 { color: #C586C0; }\n  .dark-default-dark .mtk7 { color: #B5CEA8; }\n  .dark-default-dark .mtk6 { color: #D7BA7D; }\n</style>","frontmatter":{"date":"September 21, 2020","updated_date":null,"description":"Learn how to use MongoDB as a data source for your Go application using the mongo-go driver","title":"Using MongoDB as Datasource in GoLang","tags":["Go","MongoDB"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/462778a1e1bc2468232a76699885ec69/ee604/gomongo.png","srcSet":"/static/462778a1e1bc2468232a76699885ec69/69585/gomongo.png 200w,\n/static/462778a1e1bc2468232a76699885ec69/497c6/gomongo.png 400w,\n/static/462778a1e1bc2468232a76699885ec69/ee604/gomongo.png 800w,\n/static/462778a1e1bc2468232a76699885ec69/f3583/gomongo.png 1200w,\n/static/462778a1e1bc2468232a76699885ec69/5707d/gomongo.png 1600w,\n/static/462778a1e1bc2468232a76699885ec69/eeb1b/gomongo.png 1920w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Puneet Singh","github":"puneetsingh24","avatar":null}}}},{"node":{"excerpt":"We often hear that JavaScript is a single-threaded programming language, which means it executes all of the instructions line by line in a…","fields":{"slug":"/engineering/understanding-event-loop/"},"html":"<p>We often hear that JavaScript is a single-threaded programming language, which means it executes all of the instructions line by line in a synchronous manner. Thus since everything works on the main thread, there seems to be no possibility of executing parallel processes in JavaScript.</p>\n<p>But now let's assume that we have a function which is taking some time to execute, for example in the below function which is having a loop over 10k times, the <code>console.log()</code> would be executed once the loop is over and in the meantime, our UI interaction with the browser would be interrupted.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">function</span><span class=\"mtk1\"> </span><span class=\"mtk11\">someTimeTakingFunc</span><span class=\"mtk1\">() {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk15\">for</span><span class=\"mtk1\">(</span><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">i</span><span class=\"mtk1\"> = </span><span class=\"mtk7\">0</span><span class=\"mtk1\">; </span><span class=\"mtk12\">i</span><span class=\"mtk1\"> &lt; </span><span class=\"mtk7\">10000</span><span class=\"mtk1\">; </span><span class=\"mtk12\">i</span><span class=\"mtk1\">++) {</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  }</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Loop has been executed&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span></code></pre>\n<p>The above scenario seems to be impractical, but there might be cases where any function can take an indeterminate amount of time and our main thread would be blocked, for example calling an API for fetching data from the server-side. And this is the practical use case we are dealing with in development every day. So how JavaScript handles this and where does the event loop come into the picture? We will surely get to know this, but before moving further, let's understand the basic memory architecture in JavaScript.</p>\n<h3 id=\"memory-organization-of-javascript\" style=\"position:relative;\"><a href=\"#memory-organization-of-javascript\" aria-label=\"memory organization of javascript permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Memory Organization of JavaScript:</h3>\n<p>The Javascript Engine consists of two main components:</p>\n<ul>\n<li><strong>Memory Heap</strong> — this is where the memory allocation happens, all of our object variables are assigned here in a random manner.</li>\n<li><strong>Call Stack</strong> — this is where your function calls are stored.</li>\n</ul>\n<h3 id=\"understanding-the-call-stack\" style=\"position:relative;\"><a href=\"#understanding-the-call-stack\" aria-label=\"understanding the call stack permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Understanding the Call Stack</h3>\n<p>Call stack is a LIFO (last in first out) data structure. All of the function calls are pushed into this call stack and are said to be a frame. In short function, a stack is nothing but the simple stack data structure which keeps track of the function currently being executed.</p>\n<p>Let's understand the above concept with the example of the following code snippet:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\"> </span><span class=\"mtk4\">function</span><span class=\"mtk1\"> </span><span class=\"mtk11\">square</span><span class=\"mtk1\">(</span><span class=\"mtk12\">b</span><span class=\"mtk1\">) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">   </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> </span><span class=\"mtk12\">b</span><span class=\"mtk1\"> * </span><span class=\"mtk12\">b</span><span class=\"mtk1\"> ; </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> }</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span><span class=\"mtk4\">function</span><span class=\"mtk1\"> </span><span class=\"mtk11\">cube</span><span class=\"mtk1\">(</span><span class=\"mtk12\">x</span><span class=\"mtk1\">) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">   </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> </span><span class=\"mtk12\">x</span><span class=\"mtk1\"> * </span><span class=\"mtk11\">square</span><span class=\"mtk1\">(</span><span class=\"mtk12\">x</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> }</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk11\">cube</span><span class=\"mtk1\">(</span><span class=\"mtk7\">8</span><span class=\"mtk1\">));</span></span></code></pre>\n<p>The above snippet is an example of defining a <code>cube</code>  function, which is calling a <code>square</code> function, to find the cube of a number passed in the argument. But how does this work in call stack? Let's understand step by step: </p>\n<ol>\n<li>When we call the <code>console.log()</code> line, this <code>code/function</code> is pushed into the call stack. </li>\n<li>Now the above <code>console.log()</code> function is called the <code>cube</code> function, hence this function is pushed into the stack. </li>\n<li>After this the <code>cube</code> function is calling the <code>square</code> function, and now this would be pushed into the stack. </li>\n<li>Now once the <code>square</code> function is executed, and the result is returned, then the <code>square</code> function is popped out of the stack. </li>\n<li>Since at this step, we have got the <code>square</code> function result, so <code>cube</code> function would be executed and popped out of the call stack. </li>\n<li>At last, the <code>console.log()</code> would be executed and this function would be popped out of the stack and the stack would now be empty.</li>\n</ol>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 75.07692307692308%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAIAAABr+ngCAAAACXBIWXMAAAsTAAALEwEAmpwYAAACtElEQVQoz2P4////v3//gOTnT19aqybWFXWVZjbt3HRg2/q9ZZlN1fkdE9tnnzt1uTq/vaGkuzKn9ezJS0DFf//+BZIMIM1/QZpfv3xrruqhJW4rw2HQ3TitvXoikKEmZOlpGbVu+TYgQ0/KXonXdO2yLUDFf/78gWkG2/zm9TtX0zArDW9dKfspXXMntM7Sk3YAGhfukbZl7W4DRTdTdW9tGadNa3Zh1+xiHGKp5qUjYTe5c25v8wxlEWttWWd/56Sta3fl24W1BabmWQVvXwvS/PfPXxTNb1+/czAK0VfyUBG17e+YM7d7bo5ZYKVLdFNUIdC2dveYhdFZ7W7RuzfswaL5+fM3ydZhxTYhSdpuM9pnzWie1mMfNMc/bmps/vLFW2psgmYGJddZBWxbtR2sGdXZHz58XtQ5c3nr5EX1/Ud2HN69ad/0yu65dX1rpi45feLirPoJC5smzq6fcOnMFZTQhgCgSy5euLFjx6FDB888fvT82ZOX+/ed2LXz8NUrdz5++HTyxMWdOw6dOH4RGClw+xA2v3/30ckgSF/aQYnXpLmir71mojKfqa6EnY919PaNew1kHI3kXVQEzBfNWoUltD+8/+RjE2Oh5qkr7dDVMKWvZQYwzkyV3cPcU/dsO2Sl6WOt6Wsg67R8/nqsmj8C04OxkrumuG1H3eSepunABGOs6Brikrx760ELNS9LdWAScFg2bx12zb7W0dZqngaS9p1gzUBTjBRdg4nR/PrNh6bgzGmhaa3OEfPaZ3Q0TNOTtDdTdg91TYFottLwwan55ev3rWHZ0wOTetyj5nbMnNkxq8k5vMcnbkJS6dZN+4Hp1ETJTVvCbtm8tSiaoVH199/je48unjj38Na9d2/ev3/74dbFa5dPnX/99OWXL19vXb9z4siZ2zfuAqMNbh8AzvRGF/PvU4kAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Call Stack Execution\"\n        title=\"Call Stack Execution\"\n        src=\"/static/b0cb491942181c620ef5647a09864e2e/e5715/call_stack.png\"\n        srcset=\"/static/b0cb491942181c620ef5647a09864e2e/a6d36/call_stack.png 650w,\n/static/b0cb491942181c620ef5647a09864e2e/e5715/call_stack.png 768w,\n/static/b0cb491942181c620ef5647a09864e2e/2bef9/call_stack.png 1024w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>Now since we have understood that call stacks are possible to execute the function in a step by step manner, there seems to be no possibility of keeping something into parallel. But there is something called <strong>\"WEB APIs\"</strong> in the browser environment, which is some additional capabilities provided by browsers in addition to JavaScript Engine.</p>\n<h3 id=\"javascript-web-apis\" style=\"position:relative;\"><a href=\"#javascript-web-apis\" aria-label=\"javascript web apis permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Javascript Web APIs</h3>\n<p>These are the additional functionality, that helps us perform some additional tasks which cannot be run using the main thread. However, since our JavaScript runtime is single-threaded, it can export some tasks to the WEB APIs which helps us to respond to multiple threads. Example of some web APIs are:</p>\n<ul>\n<li>DOM </li>\n<li>Ajax (Network requests)</li>\n<li>setTimeout()</li>\n</ul>\n<p>For instance, <code>setTimeout()</code> is called, the browser delegates the task to a different thread to calculate the time interval specified in the argument of the <code>setTimeout()</code> method, and once done this tread would then call the desired function in callback stack.</p>\n<p>Since JavaScript is single-threaded, the browser has the capability of delegating the task in multiple threads. But how does the event loop help in these executions? But now we are good to go ahead with Event Loop. </p>\n<h3 id=\"event-loop--event-queue\" style=\"position:relative;\"><a href=\"#event-loop--event-queue\" aria-label=\"event loop  event queue permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Event Loop &#x26;&#x26; Event Queue</h3>\n<p>Since we know that Web APIs delegate some of the tasks to different threads, on completion of these tasks, how the main or desired functions are sent to the call stack. </p>\n<p>Event Queue is a special queue, which keeps track of all the functions queues, which are needed to be pushed into the call stack.\nThe event queue is responsible for sending new functions to the track for processing. The queue data structure is required to maintain the correct sequence in which all operations should be sent for execution.</p>\n<p>Let's take an example, in the following example, we are using a <code>setTimeout</code> function, which will log the \"executed\" string after 2000 milliseconds. </p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">  </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk11\">setTimeout</span><span class=\"mtk1\">(</span><span class=\"mtk4\">function</span><span class=\"mtk1\">(){</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Executed&quot;</span><span class=\"mtk1\">;)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  }, </span><span class=\"mtk7\">2000</span><span class=\"mtk1\">);</span></span></code></pre>\n<p>Now when a setTimeout operation is processed in the call stack. On its execution, it calls a web API which fires a timer for 2000 milliseconds. After 2000 milliseconds has been elapsed, the web API, place the callback function of <code>setTimeout</code> in the event queue. </p>\n<p>Here need to mention that, just placing our function does not necessarily imply that the function will get executed. This function has to be pushed into the call stack for execution and here the event loop comes into the picture. The event loop waits for the function stack to be empty, once the call stack is empty this will push the first function from the event queue to the call stack, and in this way, the desired function will be called.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 56.30769230769231%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAAAsTAAALEwEAmpwYAAABg0lEQVQoz32SUU/CMBSF+f+vxhd9MOqLRIwmajBqVCCiiRhNhIcBQUAFBwy2ssG2tjvezs0xBW9yt9ve9svpaTOgCIIAgZSrk/rxuvAvOBCmQMD9qBWozySjRpIakvMkaSyiWvj+H6Cc2eAjHcIcQzBzCZATwCfAfAZJACkkpOtC0Fh438D4FCqG2iuKW/sobefwXqkuByoQkUKYgscRAxcVDmpNlDf2cLeZRbf8tEohbXSmBFbeSBi2jY4xhu96kKSMexycahX6Sx2FtR0U13fRKT2uAColNguPSR009AEK9SakF5oOr9eF19LUXsyZDeutD62qwRwY/3gYg0mRPZvDsh30R2OwuQsYfchRP7GCssdYbEVkBpJb/pkKNSQxtBganzpMx4FLthjMwnTmoEZzjEssyEuASlF4Mb9SPR1E71C3LHzc36J9eoL2WR6tizzcyg249oxYYHjklLKF20zVkW7j6hztbA7dg0MMjo/gXebgPVyngcsAKVCQ7q+ImDn5AruyUxa6+NHrAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Event Loop\"\n        title=\"Event Loop\"\n        src=\"/static/68b5a28f6bdca97b73593056ae425a8d/e5715/event_loop_illustration.png\"\n        srcset=\"/static/68b5a28f6bdca97b73593056ae425a8d/a6d36/event_loop_illustration.png 650w,\n/static/68b5a28f6bdca97b73593056ae425a8d/e5715/event_loop_illustration.png 768w,\n/static/68b5a28f6bdca97b73593056ae425a8d/21b4d/event_loop_illustration.png 1280w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>Thus event loop works in a cyclic manner, where it continually checks whether or not the call stack is empty. If it is empty, new functions are added from the event queue. If it is not, then the current function call is processed.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n  .dark-default-dark .mtk4 { color: #569CD6; }\n  .dark-default-dark .mtk1 { color: #D4D4D4; }\n  .dark-default-dark .mtk11 { color: #DCDCAA; }\n  .dark-default-dark .mtk15 { color: #C586C0; }\n  .dark-default-dark .mtk12 { color: #9CDCFE; }\n  .dark-default-dark .mtk7 { color: #B5CEA8; }\n  .dark-default-dark .mtk10 { color: #4EC9B0; }\n  .dark-default-dark .mtk8 { color: #CE9178; }\n</style>","frontmatter":{"date":"September 19, 2020","updated_date":null,"description":"Learn the basic concepts about the JavaScript Event Loop.","title":"Understanding event loop in JavaScript","tags":["JavaScript","event-loop","call stack","event queue","multi-threaded"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.7699115044247788,"src":"/static/b6cf96ed7545f05ed0b5cd58325c4847/ee604/index.png","srcSet":"/static/b6cf96ed7545f05ed0b5cd58325c4847/69585/index.png 200w,\n/static/b6cf96ed7545f05ed0b5cd58325c4847/497c6/index.png 400w,\n/static/b6cf96ed7545f05ed0b5cd58325c4847/ee604/index.png 800w,\n/static/b6cf96ed7545f05ed0b5cd58325c4847/f3583/index.png 1200w,\n/static/b6cf96ed7545f05ed0b5cd58325c4847/e4d72/index.png 1280w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Aman Agrawal","github":"aman-agrwl","avatar":null}}}},{"node":{"excerpt":"Have you ever thought about what the world would be like if open-source didn't exist? It's hard to imagine a world without open source these…","fields":{"slug":"/engineering/loginradius-supports-hacktoberfest-2020/"},"html":"<h2 id=\"have-you-ever-thought-about-what-the-world-would-be-like-if-open-source-didnt-exist\" style=\"position:relative;\"><a href=\"#have-you-ever-thought-about-what-the-world-would-be-like-if-open-source-didnt-exist\" aria-label=\"have you ever thought about what the world would be like if open source didnt exist permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Have you ever thought about what the world would be like if open-source didn't exist?</h2>\n<p>It's hard to imagine a world without open source these days. Open source powers the biggest organizations of today's world. Open-source software like <a href=\"https://en.wikipedia.org/wiki/Linux\">Linux</a> runs most of today's servers and also powers the <a href=\"https://en.wikipedia.org/wiki/Android_(operating_system)\">Android Operating System</a>.</p>\n<h2 id=\"introducing-hacktoberfest-2020\" style=\"position:relative;\"><a href=\"#introducing-hacktoberfest-2020\" aria-label=\"introducing hacktoberfest 2020 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Introducing Hacktoberfest 2020</h2>\n<h4 id=\"in-a-gist-hacktoberfest-is-a-festival-of-giving-back-to-the-community\" style=\"position:relative;\"><a href=\"#in-a-gist-hacktoberfest-is-a-festival-of-giving-back-to-the-community\" aria-label=\"in a gist hacktoberfest is a festival of giving back to the community permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>In a gist hacktoberfest is a festival of \"giving back to the community\".</h4>\n<p>Hacktoberfest is a month-long celebration of open-source software in October month run by DigitalOcean in partnership with GitHub and DEV. Hacktoberfest is open to everyone in our global community!</p>\n<p><strong>From Official Website:</strong></p>\n<blockquote>\n<p>Hacktoberfest is open to everyone in our global community. Whether you’re new to development, a student, long-time contributor, event host, or company of any size, you can help drive the growth of open source and make positive contributions to an ever-growing community. All backgrounds and skill levels are encouraged to complete the challenge.</p>\n</blockquote>\n<p>The purpose of this month-long celebration is to get people started in open source and give back to the open-source community.</p>\n<p>It is the easiest way to get into open source for people who have never contributed to open-source community or find it difficult to contribute.</p>\n<h3 id=\"how-to-contribute-to-hacktoberfest\" style=\"position:relative;\"><a href=\"#how-to-contribute-to-hacktoberfest\" aria-label=\"how to contribute to hacktoberfest permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How to contribute to Hacktoberfest?</h3>\n<p>Anyone can contribute to hacktoberfest by registering at <a href=\"https://hacktoberfest.digitalocean.com/\">hacktoberfest website</a> anytime between 1st October to 31st October.</p>\n<p>During this time, anyone who wishes to be part of this month-long fest needs to open four quality pull requests on any of the open-source projects on Github.</p>\n<h3 id=\"how-to-find-projects\" style=\"position:relative;\"><a href=\"#how-to-find-projects\" aria-label=\"how to find projects permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How to find Projects?</h3>\n<p>Finding projects can be a bit challenging. It can be the tools you are already using, or different tools can be used to find the issues based on various labels. Tools like <a href=\"http://issuehub.io/\">issuehub</a> are really helpful for the same.</p>\n<p>This year <a href=\"https://www.loginradius.com/\">LoginRadius</a> is going to be part of Hacktoberfest by open-sourcing a lot of its projects and accepting contributions on them including its <a href=\"https://www.loginradius.com/blog/engineering/\">Engineering Blog</a>.</p>\n<h3 id=\"getting-loginradius-branded-swags\" style=\"position:relative;\"><a href=\"#getting-loginradius-branded-swags\" aria-label=\"getting loginradius branded swags permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Getting LoginRadius branded swags</h3>\n<p>Like I said, this year <strong>LoginRadius</strong> will be part of hacktoberfest and yes, we are here with some <strong>cool swags.</strong> We have got around <strong>500 t-shirts</strong> for people contributing to our open source repositories. We will soon share details on how to get LoginRadius swags as well as our open source repositories on our <a href=\"https://www.loginradius.com/blog/async\">Blog</a>.</p>\n<p>Stay tuned and <strong>don’t forget to mention your open-source projects for us to contribute.</strong></p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n</style>","frontmatter":{"date":"September 18, 2020","updated_date":null,"description":"Open Source is changing the world, One Pull Request at a time. Join LoginRadius this year in supporting hacktoerbest 2020 by contributing to open source and get cool swags from LoginRadius","title":"LoginRadius Supports Hacktoberfest 2020","tags":["hacktoberfest","open-source","LoginRadius"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5873015873015872,"src":"/static/ccafb9d75be0248e67ee6c688fd6cee5/ee604/hacktober-fest-banner.png","srcSet":"/static/ccafb9d75be0248e67ee6c688fd6cee5/69585/hacktober-fest-banner.png 200w,\n/static/ccafb9d75be0248e67ee6c688fd6cee5/497c6/hacktober-fest-banner.png 400w,\n/static/ccafb9d75be0248e67ee6c688fd6cee5/ee604/hacktober-fest-banner.png 800w,\n/static/ccafb9d75be0248e67ee6c688fd6cee5/31987/hacktober-fest-banner.png 1000w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Hridayesh Sharma","github":"vyasriday","avatar":null}}}},{"node":{"excerpt":"Businesses need to keep their consumers loyal to their products, services, and the brands, at large—which is why an efficient consumer…","fields":{"slug":"/identity/loginradius-identity-experience-framework/"},"html":"<p>Businesses need to keep their consumers loyal to their products, services, and the brands, at large—which is why an efficient consumer interface is the need of the hour. It can deliver consumer experiences that are most conducive to the success of any business.</p>\n<p>Our recently launched <a href=\"https://www.loginradius.com/identity-experience-framework/\">Identity Experience Framework</a> is a powerful orchestration feature that can be used to quickly implement any customization required on your identity page. It also meets the critical customization, formatting, design, and authentication demands of all businesses.</p>\n<h2 id=\"intent-behind-the-launch\" style=\"position:relative;\"><a href=\"#intent-behind-the-launch\" aria-label=\"intent behind the launch permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Intent Behind the Launch</h2>\n<p>We wanted businesses to enjoy a hassle-free authentication and customization of identity pages, alongside <a href=\"https://www.loginradius.com/customer-experience-solutions/\">delivering consumer experiences</a> at its best.</p>\n<p>Hence, our LoginRadius Identity Experience Framework  benefits businesses in the following ways: </p>\n<ul>\n<li><strong>Increase consumer interaction</strong>: When implemented correctly, the feature offers a better consumer interface and experience. It also increases consumer satisfaction and interaction coherently. </li>\n<li><strong>Boost reputation and revenues</strong>: It offers collaborated designing and technical skills to deliver exceptional consumer experiences. Consequently, it boosts business reputation and amplifies the scope of revenue. </li>\n<li><strong>Builds trust and loyalty</strong>: By customizing the consumer interface to the business needs and as per consumers' demand, it is more likely to build loyalty and trust for consumers, and attract more traffic.</li>\n<li><strong>Centralized implementation</strong>: In the case of multiple applications, the Identity Experience Framework facilitates centralized <a href=\"https://www.loginradius.com/authentication/\">authentication too</a>. </li>\n</ul>\n<h2 id=\"key-capabilities-of-loginradius-identity-experience-framework\" style=\"position:relative;\"><a href=\"#key-capabilities-of-loginradius-identity-experience-framework\" aria-label=\"key capabilities of loginradius identity experience framework permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Key Capabilities of LoginRadius Identity Experience Framework</h2>\n<p><a href=\"https://www.loginradius.com/resource/loginradius-identity-experience-framework-datasheet\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 30.307692307692307%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAAAsTAAALEwEAmpwYAAABmUlEQVQY0z2Qyy+jYRTGP4vSm2szOsQt6lJFpeor/dzbamkRNpNKmIXFJC47G8mwEglWFv4AsZEwm8mwkJDYSEQjERmTWJiM8A+wmDE2P+f7lDd53rznvM85z3OOYqnpQIe1thO7uwt7XRc2dye2Wsml/95grtKw1ofIV4coaAxh8Qjc3Viq2985in7ZpJnDGya7rttoYhOSw9ePU02QU9+LWQp0ZLnasDb2URYZxxP+hFkdxdTQJ/kgWVWvHOWtc4U2TGDwM95oEk8kiV2cZPvi5HijhjPdfbEapyI4RLE/hlNQFhiQeJCS1gS5Imw4NKftujpG0EYm8ScmaIqNURqIU9QyQF5DSNQ1Cn1RCpujOJoifJC3sznGR3+/5GIUyHQ6Vxc1HGZKwda3fW7+3JG6+Mn55RWXv675fXuPNjpJRrmKUtrC7OIaZxdXbH8/YHP3h4GjkxQ7e4eGQ5OMrlhl+abKIMen5+jn8fGBp39/ef7/ZMSh5BRKiZ9Ml0Z4bJr5lQ1mFlaZ/qpjhbmldb7ML8uue4xJXgDBYt9x1EO7kwAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"IDX Product\"\n        title=\"IDX Product\"\n        src=\"/static/f73e278445b9e70d70f63f08116d12f9/e5715/IDX-Product.png\"\n        srcset=\"/static/f73e278445b9e70d70f63f08116d12f9/a6d36/IDX-Product.png 650w,\n/static/f73e278445b9e70d70f63f08116d12f9/e5715/IDX-Product.png 768w,\n/static/f73e278445b9e70d70f63f08116d12f9/2bef9/IDX-Product.png 1024w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<p><strong>Predefined themes</strong>: It offers predefined themes designed to fit all business requirements as per industry standards. </p>\n<p><strong>Ready-to-use scripts</strong>: It offers complete customization, formatting, design for all authentication-related pages, along with quick replaceable scripts for pages like login, registration, forgot password, etc.</p>\n<p><strong>Customizable solution</strong>: While the Basic Editor allows the customization of the background image, logo color, content customization for sign up page, etc., Advanced Editor allows prompt changes via \"Replace\" options like complete customization, design via HTML, CSS, Javascript for login, registration pages, etc. </p>\n<p><strong>Branding preview</strong>: It offers real-time preview for the customization made to logos, images, etc. to visualize the change before implementing it.</p>\n<p><strong>Quick implementation</strong>: It handles and manages implementation in a very efficient and smooth manner.</p>\n<h2 id=\"a-final-word\" style=\"position:relative;\"><a href=\"#a-final-word\" aria-label=\"a final word permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>A Final Word</h2>\n<p>With the LoginRadius Identity Experience Framework, businesses can enjoy a complete set of customizable solutions and provide consumers with seamless experiences. Be it, tweaking the authentication flow or changing the interface designs—this feature can do them all. </p>\n<p><a href=\"https://www.loginradius.com/book-a-demo/\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 30.307692307692307%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAAAsTAAALEwEAmpwYAAABbElEQVQY0zVQO0/CUBQmaihthUbRhPhCAlhKEXlE3s+CCEaBwQF10riQODkwaFyMMcTFwR9gjBvRSeKko4NxcfD/fJ57C8PJbc53+r0soj8Lm5qHbS0HW6AIwZ+DXSvAESxBpJ3MMLph3+xWDlUwm2jCGa5A0isQtRIkhrH/CbdwwkDBHAJlGodexsy6wUkduknMBCfdmxCCBhZKHailfUxGm5jQKphaTUDwmaIWdigyF1oZsm7AFavBRspKuMpdTJMQO5yLbCHVPkG0cYRY4xAR9tbp3T5AsnUMT7YFqzdtOuQOSFmiyMupXUihKuzk0hWvc0xgUYlYod18tAZPrg13eg8rNIuJHSihMtVUHEUe51cLPJ5zo8oJJRJQRnHlQB6WpTjOru7w/fuH59d3PL0M8Th4w+fXDwbDD16R1ZsxCcelsyUbidQEEuC9ECap1J8nCaPTRe/2Ad3LvjkXfZxf3+O0d8P7FnwZ/AMzEsMp2f6LdQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"book-a-free-demo-loginradius\"\n        title=\"book-a-free-demo-loginradius\"\n        src=\"/static/779ad148d33fb1ecfd80cc41f1a94ef3/e5715/Book-a-free-demo-request.png\"\n        srcset=\"/static/779ad148d33fb1ecfd80cc41f1a94ef3/a6d36/Book-a-free-demo-request.png 650w,\n/static/779ad148d33fb1ecfd80cc41f1a94ef3/e5715/Book-a-free-demo-request.png 768w,\n/static/779ad148d33fb1ecfd80cc41f1a94ef3/2bef9/Book-a-free-demo-request.png 1024w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n</style>","frontmatter":{"date":"September 18, 2020","updated_date":null,"description":"Overall, companies need to keep their customers loyal to their goods, services , and brands — which is why the need for the hour is an effective user interface. It can have customer interactions that are most conducive to any company's success.","title":"Announcement - LoginRadius Delivers Exceptional Authentication With The Launch Of Identity Experience Framework","tags":["authentication","identity management","cx"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.408450704225352,"src":"/static/d718daf5925a8567f77fc8817a7c346e/6051d/IDx.png","srcSet":"/static/d718daf5925a8567f77fc8817a7c346e/69585/IDx.png 200w,\n/static/d718daf5925a8567f77fc8817a7c346e/497c6/IDx.png 400w,\n/static/d718daf5925a8567f77fc8817a7c346e/6051d/IDx.png 769w","sizes":"(max-width: 769px) 100vw, 769px"}}},"author":{"id":"Karl Wittig","github":null,"avatar":null}}}}]},"markdownRemark":{"excerpt":"Identity is evolving, and developers are at the forefront of this transformation. Every day brings a new learning—adapting to new standards…","fields":{"slug":"/identity/developer-first-identity-provider-loginradius/"},"html":"<p>Identity is evolving, and developers are at the forefront of this transformation. Every day brings a new learning—adapting to new standards and refining approaches to building secure, seamless experiences.</p>\n<p>We’re here to support developers on that journey. We know how important simplicity, efficiency, and well-structured documentation are when working with identity and access management solutions. That’s why we’ve redesigned the <a href=\"https://www.loginradius.com/\">LoginRadius website</a>—to be faster, more intuitive, and developer-first in every way.</p>\n<p>The goal? Having them spend less time searching and more time building.</p>\n<h2 id=\"whats-new-and-improved-on-the-loginradius-website\" style=\"position:relative;\"><a href=\"#whats-new-and-improved-on-the-loginradius-website\" aria-label=\"whats new and improved on the loginradius website permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What’s New and Improved on the LoginRadius Website?</h2>\n<p>LoginRadius’ vision is to give developers a product that simplifies identity management so they can focus on building, deploying, and scaling their applications. To enhance this experience, we’ve spent the last few months redesigning our interface— making navigation more intuitive and reassuring that essential resources are easily accessible.</p>\n<p>Here’s a closer look at what’s new and why it’s important:</p>\n<h3 id=\"a-developer-friendly-dark-theme\" style=\"position:relative;\"><a href=\"#a-developer-friendly-dark-theme\" aria-label=\"a developer friendly dark theme permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>A Developer-Friendly Dark Theme</h3>\n<p><img src=\"/f46881583c7518a93bb24e94c32320de/a-developer-friendly-dark-theme.webp\" alt=\"This image shows how LoginRadius offers several authentication methods like traditional login, social login, passwordless login, passkeys and more in a dark mode.\">    </p>\n<p>Developers spend long hours working in dark-themed IDEs and terminals, so we’ve designed the LoginRadius experience to be developer-friendly and align with that preference.</p>\n<p>The new dark mode reduces eye strain, enhances readability, and provides a seamless transition between a coding environment and our platform. Our new design features a clean, modern aesthetic with a consistent color scheme and Barlow typography, ensuring better readability. High-quality graphics and icons are thoughtfully placed to enhance the content without adding visual clutter.</p>\n<p>So, whether you’re navigating our API docs or configuring authentication into your system, our improved interface will make those extended development hours more comfortable and efficient.</p>\n<h3 id=\"clear-categorization-for-loginradius-capabilities\" style=\"position:relative;\"><a href=\"#clear-categorization-for-loginradius-capabilities\" aria-label=\"clear categorization for loginradius capabilities permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Clear Categorization for LoginRadius Capabilities</h3>\n<p><img src=\"/e5358b82be414940f3fb146013845933/capabilities.webp\" alt=\"This image shows a breakdown of all the LoginRadius CIAM capabilities, including authentication, security, UX, scalability and multi-brand management.\"></p>\n<p>We’ve restructured our website to provide a straightforward breakdown of our customer identity and access management platform capabilities, helping you quickly find what you need:</p>\n<ul>\n<li>Authentication: Easily understand <a href=\"https://www.loginradius.com/blog/identity/authentication-option-for-your-product/\">how to choose the right login method</a>, from traditional passwords and OTPs to social login, federated SSO, and passkeys with few lines of code.</li>\n<li>Security: Implement no-code security features like bot detection, IP throttling, breached password alerts, DDoS protection, and adaptive MFA to safeguard user accounts.</li>\n<li>User Experience: Leverage AI builder, hosted pages, and drag-and-drop workflows to create smooth, branded sign-up and login experiences.</li>\n<li>High Performance &#x26; Scalability: Confidently scale with sub-100ms API response times, 100% uptime, 240K+ RPS, and 28+ global data center regions.</li>\n<li>Multi-Brand Management: Efficiently manage multiple identity apps, choosing isolated or shared data stores based on your brand’s unique needs.</li>\n</ul>\n<p>This structured layout ensures you can quickly understand each capability and how it integrates into your identity ecosystem.</p>\n<h3 id=\"developer-first-navigation\" style=\"position:relative;\"><a href=\"#developer-first-navigation\" aria-label=\"developer first navigation permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Developer-First Navigation</h3>\n<p><img src=\"/a8c155c2b6faf3d5f4b4de4e2b14d763/developers-menu.webp\" alt=\"This image shows the LoginRadius menu bar, highlighting the developer dropdown.\">   </p>\n<p>We’ve been analyzing developer workflows to identify how you access key resources. That’s why we redesigned our navigation with one goal in mind: to reduce clicks and make essential resources readily available.</p>\n<p>The new LoginRadius structure puts APIs, SDKs, and integration guides right at the menu bar under the Developers dropdown so you can get started faster. Our Products, Solutions, and Customer Services are also clearly categorized, helping development teams quickly find the right tools and make informed decisions.</p>\n<h3 id=\"quick-understanding-of-integration-benefits\" style=\"position:relative;\"><a href=\"#quick-understanding-of-integration-benefits\" aria-label=\"quick understanding of integration benefits permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Quick Understanding of Integration Benefits</h3>\n<p><img src=\"/b2f9a964a2da0ea83e2f8596b833bba7/we-support-your-tech-stack.webp\" alt=\"This image shows a list of popular programming languages and frameworks offered by LoginRadius.\"></p>\n<p>Developers now have a clear view of the tech stack available with LoginRadius, designed to support diverse business needs.</p>\n<p>Our platform offers pre-built SDKs for Node.js, Python, Java, and more, making CIAM integration seamless across popular programming languages and frameworks.</p>\n<h2 id=\"over-to-you-now\" style=\"position:relative;\"><a href=\"#over-to-you-now\" aria-label=\"over to you now permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Over to You Now!</h2>\n<p>Check out our <a href=\"https://www.loginradius.com/\">revamped LoginRadius website</a> and see how the improved experience makes it easier to build, scale, and secure your applications.</p>\n<p>Do not forget to explore the improved navigation and API documentation, and get started with our free trial today. We’re excited to see what you’ll build with LoginRadius!</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n</style>","frontmatter":{"date":"February 21, 2025","updated_date":null,"description":"LoginRadius’ vision is to give developers a product that simplifies identity management so they can focus on building, deploying, and scaling their applications. To enhance this experience, we’ve redesigned our website interface, making navigation more intuitive and reassuring that essential resources are easily accessible.","title":"Revamped & Ready: Introducing the New Developer-First LoginRadius Website","tags":["Developer tools","API","Identity Management","User Authentication"],"pinned":true,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.7857142857142858,"src":"/static/80b4e4fbe176a10a327d273504607f32/58556/hero-section.webp","srcSet":"/static/80b4e4fbe176a10a327d273504607f32/61e93/hero-section.webp 200w,\n/static/80b4e4fbe176a10a327d273504607f32/1f5c5/hero-section.webp 400w,\n/static/80b4e4fbe176a10a327d273504607f32/58556/hero-section.webp 800w,\n/static/80b4e4fbe176a10a327d273504607f32/99238/hero-section.webp 1200w,\n/static/80b4e4fbe176a10a327d273504607f32/7c22d/hero-section.webp 1600w,\n/static/80b4e4fbe176a10a327d273504607f32/1258b/hero-section.webp 2732w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Rakesh Soni","github":"oyesoni","avatar":"rakesh-soni.jpg"}}}},"pageContext":{"limit":6,"skip":714,"currentPage":120,"type":"///","numPages":161,"pinned":"ee8a4479-3471-53b1-bf62-d0d8dc3faaeb"}},"staticQueryHashes":["1171199041","1384082988","2100481360","23180105","528864852"]}