{"componentChunkName":"component---src-templates-blog-list-template-js","path":"/engineering/43","result":{"data":{"allMarkdownRemark":{"edges":[{"node":{"excerpt":"While creating Lead Generation form at LoginRadius, Marketers wanted to sure that visitors enter business emails. To that end, I created a…","fields":{"slug":"/engineering/open-source-business-email-validator-by-loginradius/"},"html":"<p>While creating Lead Generation form at LoginRadius, Marketers wanted to sure that visitors enter business emails. To that end, I created a list in JSON format to block free mail providers like Gmail, Outlook etc.</p>\n<p>Business mail validator makes sure users enters only business emails in submission forms on a web page. User can’t enter with free email’s that provided by the third party (free email) service provider.</p>\n<p>Ex. Gmail.com, Yahoo.com, Yahoomail.com, Rediff.com etc.</p>\n<p>We can classified business email validation in two ways.</p>\n<h3 id=\"1-client-side\" style=\"position:relative;\"><a href=\"#1-client-side\" aria-label=\"1 client side 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><strong>1. Client side</strong></h3>\n<p>In client side validation we use javascript(js) OR jQuery to validate entered the email at time of submission the html form. So we can follow the following steps to validate it on client side.</p>\n<ul>\n<li>First of all create a simple html page with name emailvalidate.html</li>\n<li>\n<p>Add jQuery script on head section</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">script</span><span class=\"mtk1\"> </span><span class=\"mtk12\">src</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js&quot;</span><span class=\"mtk17\">&gt;&lt;/</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n</li>\n<li>Call json file content in a script variable like</li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    var emailValidator = </span><span class=\"mtk4\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk8\">&quot;123.com&quot;</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=\"mtk8\">&quot;123box.net&quot;</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=\"mtk8\">&quot;123india.com&quot;</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>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        …………………..</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk8\">&quot;ymail.com&quot;</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=\"mtk8\">&quot;yandex.com&quot;</span><span class=\"mtk1\">: </span><span class=\"mtk4\">true</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk4\">}</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>Our complete list is available <a href=\"https://github.com/LoginRadius/business-email-validator/blob/master/src/freeEmailService.json\">here</a></p>\n<ul>\n<li>Add validation form function after you have added above code.</li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">function validateForm(id) </span><span class=\"mtk4\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                            </span><span class=\"mtk12\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">emailValue</span><span class=\"mtk1\"> = </span><span class=\"mtk11\">jQuery</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;#&#39;</span><span class=\"mtk1\">+</span><span class=\"mtk12\">id</span><span class=\"mtk1\">).</span><span class=\"mtk11\">val</span><span class=\"mtk1\">();</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                            </span><span class=\"mtk12\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">emailArray</span><span class=\"mtk1\"> = </span><span class=\"mtk12\">emailValue</span><span class=\"mtk1\">.</span><span class=\"mtk11\">split</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;@&quot;</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                            </span><span class=\"mtk12\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">provider</span><span class=\"mtk1\"> = </span><span class=\"mtk12\">emailArray</span><span class=\"mtk1\">[</span><span class=\"mtk7\">1</span><span class=\"mtk1\">] ? </span><span class=\"mtk12\">emailArray</span><span class=\"mtk1\">[</span><span class=\"mtk7\">1</span><span class=\"mtk1\">] : </span><span class=\"mtk8\">&#39;&#39;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                            </span><span class=\"mtk11\">for</span><span class=\"mtk1\">(</span><span class=\"mtk12\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">domain</span><span class=\"mtk1\"> </span><span class=\"mtk4\">in</span><span class=\"mtk1\"> </span><span class=\"mtk12\">emailValidator</span><span class=\"mtk1\">){</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                            </span><span class=\"mtk11\">if</span><span class=\"mtk1\">(</span><span class=\"mtk12\">emailValidator</span><span class=\"mtk1\">[</span><span class=\"mtk12\">domain</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=\"mtk12\">domain</span><span class=\"mtk1\"> == </span><span class=\"mtk12\">provider</span><span class=\"mtk1\">){</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                                                        </span><span class=\"mtk11\">alert</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Please Provide Business Email Address.&quot;</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>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                           }</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span><span class=\"mtk12\">return</span><span class=\"mtk1\"> </span><span class=\"mtk4\">true</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<ul>\n<li><strong>Create html form</strong></li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">form</span><span class=\"mtk1\"> </span><span class=\"mtk12\">name</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;myForm&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk12\">action</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;emailsubmit.php&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk12\">onsubmit</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;return validateForm(&#39;business_email&#39;);&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk12\">method</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;post&quot;</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">input</span><span class=\"mtk1\"> </span><span class=\"mtk12\">type</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;text&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk12\">placeholder</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;Full Name&quot;</span><span class=\"mtk17\">/&gt;&lt;</span><span class=\"mtk4\">br</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">input</span><span class=\"mtk1\"> </span><span class=\"mtk12\">type</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;email&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk12\">id</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;business_email&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk12\">name</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;email&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk12\">placeholder</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;Email Address&quot;</span><span class=\"mtk17\">/&gt;&lt;</span><span class=\"mtk4\">br</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">input</span><span class=\"mtk1\"> </span><span class=\"mtk12\">type</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;submit&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk12\">value</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;submit&quot;</span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">form</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>Note: if you have already have html form where you want to apply this avalidator, look up for the buysiness_email and replace it accordingly.</p>\n<ul>\n<li>Save the file and try to execute this html page on a browser.</li>\n</ul>\n<h3 id=\"2-server-side\" style=\"position:relative;\"><a href=\"#2-server-side\" aria-label=\"2 server side 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><strong>2. Server side</strong></h3>\n<p>In Server side validation we use php scripting language to validate entered email at time of submission the html form. So we can flow the following steps to validate it.</p>\n<ul>\n<li>Create a php page with name of emailsubmit.php</li>\n<li>Receive email in php post method by following code.</li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"php\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">&lt;?php</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">$email</span><span class=\"mtk1\"> = </span><span class=\"mtk11\">isset</span><span class=\"mtk1\">(</span><span class=\"mtk12\">$_POST</span><span class=\"mtk1\">[‘email’]) ? </span><span class=\"mtk11\">trim</span><span class=\"mtk1\">(</span><span class=\"mtk12\">$_POST</span><span class=\"mtk1\">[‘email’]):’’;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\">(!</span><span class=\"mtk11\">empty</span><span class=\"mtk1\">(</span><span class=\"mtk12\">$email</span><span class=\"mtk1\">)){</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                 </span><span class=\"mtk12\">$tempEmail</span><span class=\"mtk1\"> = </span><span class=\"mtk11\">explode</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;@&#39;</span><span class=\"mtk1\">, </span><span class=\"mtk12\">$email</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=\"mtk11\">isset</span><span class=\"mtk1\">(</span><span class=\"mtk12\">$tempEmail</span><span class=\"mtk1\">[</span><span class=\"mtk8\">&#39;1&#39;</span><span class=\"mtk1\">]) && !</span><span class=\"mtk11\">empty</span><span class=\"mtk1\">(</span><span class=\"mtk12\">$tempEmail</span><span class=\"mtk1\">[</span><span class=\"mtk8\">&#39;1&#39;</span><span class=\"mtk1\">])) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                 </span><span class=\"mtk12\">$validEmail</span><span class=\"mtk1\"> = </span><span class=\"mtk11\">json_decode</span><span class=\"mtk1\">(</span><span class=\"mtk11\">file_get_contents</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;freeEmailService.json&#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=\"mtk15\">if</span><span class=\"mtk1\"> (</span><span class=\"mtk11\">is_array</span><span class=\"mtk1\">(</span><span class=\"mtk12\">$validEmail</span><span class=\"mtk1\">) && </span><span class=\"mtk11\">in_array</span><span class=\"mtk1\">(</span><span class=\"mtk12\">$tempEmail</span><span class=\"mtk1\">[</span><span class=\"mtk8\">&#39;1&#39;</span><span class=\"mtk1\">], </span><span class=\"mtk11\">array_keys</span><span class=\"mtk1\">(</span><span class=\"mtk12\">$validEmail</span><span class=\"mtk1\">))) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                     </span><span class=\"mtk11\">echo</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;Please use business email address.&quot;</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 class=\"mtk1\">}</span><span class=\"mtk15\">else</span><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                     </span><span class=\"mtk11\">echo</span><span class=\"mtk1\"> ‘email is required field.’;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">?&gt;</span></span></code></pre>\n<ul>\n<li>Save file and upload on server</li>\n</ul>\n<p>Feel free to add, edit or modify this script as per your requirements. You can contact us if you have any queries.</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 .mtk17 { color: #808080; }\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 .mtk8 { color: #CE9178; }\n  .dark-default-dark .mtk11 { color: #DCDCAA; }\n  .dark-default-dark .mtk7 { color: #B5CEA8; }\n  .dark-default-dark .mtk15 { color: #C586C0; }\n</style>","frontmatter":{"date":"April 25, 2017","updated_date":null,"description":null,"title":"Open Source Business Email Validator By Loginradius","tags":["Engineering"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":0.746268656716418,"src":"/static/a657ff09e846d7d100b0fae0ea7714e9/fa668/Open-Source-Business-Validator-By-Loginradius.webp","srcSet":"/static/a657ff09e846d7d100b0fae0ea7714e9/61e93/Open-Source-Business-Validator-By-Loginradius.webp 200w,\n/static/a657ff09e846d7d100b0fae0ea7714e9/fa668/Open-Source-Business-Validator-By-Loginradius.webp 377w","sizes":"(max-width: 377px) 100vw, 377px"}}},"author":{"id":"Team LoginRadius","github":"LoginRadius","avatar":null}}}},{"node":{"excerpt":"POPUPS! They can annoy you but if used properly, they can be a boon to any marketing campaign. In 2015, Taylor wrote an article on best…","fields":{"slug":"/engineering/the-ultimate-guide-to-website-pop-ups/"},"html":"<p>POPUPS! They can annoy you but if used properly, they can be a boon to any marketing campaign. In 2015, Taylor wrote an article on best practices to use popup. While the article discussed how to optimize popup, in this article I am going to list down the types of articles and how you can implement them. I have added codes for every type of popup for a better idea.</p>\n<h3 id=\"1-creating-a-basic-popup\" style=\"position:relative;\"><a href=\"#1-creating-a-basic-popup\" aria-label=\"1 creating a basic popup 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><strong>1. Creating a basic popup:</strong></h3>\n<p><img src=\"/bd47340195d928fb4ee883951c59b738/Creating-a-simple-pop-up.webp\" alt=\"Creating a simple pop-up\"></p>\n<p>This section talks about creating a basic popup using simple HTML and CSS. There is a separate section for header, footer and content. I have also added a close button at top right corner of the popup. There are three steps to create this popup.</p>\n<h4 id=\"a-add-html-manage-a-structure-of-a-popup\" style=\"position:relative;\"><a href=\"#a-add-html-manage-a-structure-of-a-popup\" aria-label=\"a add html manage a structure of a popup 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><strong>A. Add HTML [manage a structure of a popup]</strong></h4>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;</span><span class=\"mtk12\">div</span><span class=\"mtk1\"> </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;popup-content&quot;</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;</span><span class=\"mtk12\">span</span><span class=\"mtk1\"> </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;popup-close&quot;</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">times</span><span class=\"mtk1\">;&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;/</span><span class=\"mtk12\">span</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;</span><span class=\"mtk12\">div</span><span class=\"mtk1\"> </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;popup-header&quot;</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span><span class=\"mtk12\">Header</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;/</span><span class=\"mtk12\">div</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;</span><span class=\"mtk12\">div</span><span class=\"mtk1\"> </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;popup-body&quot;</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;</span><span class=\"mtk12\">p</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span><span class=\"mtk12\">Your</span><span class=\"mtk1\"> </span><span class=\"mtk12\">popup</span><span class=\"mtk1\"> </span><span class=\"mtk12\">code</span><span class=\"mtk1\"> </span><span class=\"mtk12\">goes</span><span class=\"mtk1\"> </span><span class=\"mtk12\">here</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;/</span><span class=\"mtk12\">p</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;/</span><span class=\"mtk12\">div</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;</span><span class=\"mtk12\">div</span><span class=\"mtk1\"> </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;popup-footer&quot;</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span><span class=\"mtk12\">Footer</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;/</span><span class=\"mtk12\">div</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;/</span><span class=\"mtk12\">div</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;/</span><span class=\"mtk12\">div</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;\\</span></span></code></pre>\n<h4 id=\"b-add-css-display-like-a-popup\" style=\"position:relative;\"><a href=\"#b-add-css-display-like-a-popup\" aria-label=\"b add css display like a popup 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><strong>B. Add CSS [Display Like a popup]</strong></h4>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"css\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">&amp;amp;lt;style&amp;amp;gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk6\">.popup-layout</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">position</span><span class=\"mtk1\">: </span><span class=\"mtk8\">fixed</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">z-index</span><span class=\"mtk1\">: </span><span class=\"mtk7\">1</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">left</span><span class=\"mtk1\">: </span><span class=\"mtk7\">0</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">top</span><span class=\"mtk1\">: </span><span class=\"mtk7\">0</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">width</span><span class=\"mtk1\">: </span><span class=\"mtk7\">100%</span><span class=\"mtk1\"> ;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">height</span><span class=\"mtk1\">: </span><span class=\"mtk7\">100%</span><span class=\"mtk1\"> ;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">overflow</span><span class=\"mtk1\">: </span><span class=\"mtk8\">auto</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">background-color</span><span class=\"mtk1\">: </span><span class=\"mtk11\">rgb</span><span class=\"mtk1\">(</span><span class=\"mtk7\">0</span><span class=\"mtk1\">, </span><span class=\"mtk7\">0</span><span class=\"mtk1\">, </span><span class=\"mtk7\">0</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">background-color</span><span class=\"mtk1\">: </span><span class=\"mtk11\">rgba</span><span class=\"mtk1\">(</span><span class=\"mtk7\">0</span><span class=\"mtk1\">, </span><span class=\"mtk7\">0</span><span class=\"mtk1\">, </span><span class=\"mtk7\">0</span><span class=\"mtk1\">, </span><span class=\"mtk7\">0.4</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk6\">.popup-header</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk6\">.popup-footer</span><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">background</span><span class=\"mtk1\">: </span><span class=\"mtk8\">#29f</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">padding</span><span class=\"mtk1\">: </span><span class=\"mtk7\">20px</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">color</span><span class=\"mtk1\">: </span><span class=\"mtk8\">#fff</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">font-weight</span><span class=\"mtk1\">: </span><span class=\"mtk8\">bold</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk6\">.popup-body</span><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">padding</span><span class=\"mtk1\">: </span><span class=\"mtk7\">20px</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk6\">.popup-content</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">background-color</span><span class=\"mtk1\">: </span><span class=\"mtk8\">#fefefe</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">margin</span><span class=\"mtk1\">: </span><span class=\"mtk7\">15%</span><span class=\"mtk1\"> </span><span class=\"mtk8\">auto</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">border</span><span class=\"mtk1\">: </span><span class=\"mtk7\">1px</span><span class=\"mtk1\"> </span><span class=\"mtk8\">solid</span><span class=\"mtk1\"> </span><span class=\"mtk8\">#888</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">width</span><span class=\"mtk1\">: </span><span class=\"mtk7\">60%</span><span class=\"mtk1\"> ;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk6\">.popup-close</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">color</span><span class=\"mtk1\">: </span><span class=\"mtk8\">#FFF</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">margin</span><span class=\"mtk1\">: </span><span class=\"mtk7\">10px</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">float</span><span class=\"mtk1\">: </span><span class=\"mtk8\">right</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">font-size</span><span class=\"mtk1\">: </span><span class=\"mtk7\">28px</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">font-weight</span><span class=\"mtk1\">: </span><span class=\"mtk8\">bold</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk6\">.popup-close:hover</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk6\">.popup-close:focus</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">color</span><span class=\"mtk1\">: </span><span class=\"mtk8\">black</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">text-decoration</span><span class=\"mtk1\">: </span><span class=\"mtk8\">none</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">cursor</span><span class=\"mtk1\">: </span><span class=\"mtk8\">pointer</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">&amp;amp;lt;/style&amp;amp;gt;</span></span></code></pre>\n<p>Moreover, you can also check out this tutorial of <a href=\"/simple-popup-tutorial/\">creating a basic popup</a> if you want to learn the basic understanding.</p>\n<h4 id=\"c-add-script-for-action-on-close-button\" style=\"position:relative;\"><a href=\"#c-add-script-for-action-on-close-button\" aria-label=\"c add script for action on close button 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><strong>C. Add Script [for action on close button]</strong></h4>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;</span><span class=\"mtk12\">script</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">popup</span><span class=\"mtk1\">\\_close = </span><span class=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk11\">getElementsByClassName</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;popup-close&#39;</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><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\"> &</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">; </span><span class=\"mtk12\">popup</span><span class=\"mtk1\">\\</span><span class=\"mtk12\">_close</span><span class=\"mtk1\">.</span><span class=\"mtk12\">length</span><span class=\"mtk1\">; </span><span class=\"mtk12\">i</span><span class=\"mtk1\">++) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">closeThis</span><span class=\"mtk1\"> = </span><span class=\"mtk12\">popup</span><span class=\"mtk1\">\\</span><span class=\"mtk12\">_close</span><span class=\"mtk1\">\\[</span><span class=\"mtk12\">i</span><span class=\"mtk1\">\\];</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">closeThis</span><span class=\"mtk1\">.</span><span class=\"mtk11\">addEventListener</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;click&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk4\">function</span><span class=\"mtk1\"> () {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk11\">getElementsByClassName</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;popup-layout&#39;</span><span class=\"mtk1\">)\\[</span><span class=\"mtk7\">0</span><span class=\"mtk1\">\\].</span><span class=\"mtk12\">style</span><span class=\"mtk1\">.</span><span class=\"mtk12\">display</span><span class=\"mtk1\"> = </span><span class=\"mtk8\">&quot;none&quot;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><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 class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;/</span><span class=\"mtk12\">script</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span></code></pre>\n<h3 id=\"2-creating-a-timer-based-popup\" style=\"position:relative;\"><a href=\"#2-creating-a-timer-based-popup\" aria-label=\"2 creating a timer based popup 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><strong>2. Creating a timer based popup:</strong></h3>\n<p><img src=\"/4a93f6818c189a0fb1ca01cb37f962ff/Creating-a-timer-based-popup.gif\" alt=\"Creating a timer based popup\"></p>\n<p>This is a timer based popup which can be displayed at a certain time after the page is loaded.</p>\n<p>For reference, I have added the code to display the popup after 5 second [Add following code]. Steps are as below.</p>\n<p>Follow all the steps mentioned in section 1. (Creating a simple popup) and add the following code below that code.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;</span><span class=\"mtk12\">script</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk11\">getElementsByClassName</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;popup-layout&#39;</span><span class=\"mtk1\">)\\[</span><span class=\"mtk7\">0</span><span class=\"mtk1\">\\].</span><span class=\"mtk12\">style</span><span class=\"mtk1\">.</span><span class=\"mtk12\">display</span><span class=\"mtk1\"> = </span><span class=\"mtk8\">&quot;none&quot;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><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=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk11\">getElementsByClassName</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;popup-layout&#39;</span><span class=\"mtk1\">)\\[</span><span class=\"mtk7\">0</span><span class=\"mtk1\">\\].</span><span class=\"mtk12\">style</span><span class=\"mtk1\">.</span><span class=\"mtk12\">display</span><span class=\"mtk1\"> = </span><span class=\"mtk8\">&quot;block&quot;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}, </span><span class=\"mtk7\">5000</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;/</span><span class=\"mtk12\">script</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span></code></pre>\n<p>To Auto hide after 5 second, add following code.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;</span><span class=\"mtk12\">script</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk11\">getElementsByClassName</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;popup-layout&#39;</span><span class=\"mtk1\">)\\[</span><span class=\"mtk7\">0</span><span class=\"mtk1\">\\].</span><span class=\"mtk12\">style</span><span class=\"mtk1\">.</span><span class=\"mtk12\">display</span><span class=\"mtk1\"> = </span><span class=\"mtk8\">&quot;block&quot;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><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=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk11\">getElementsByClassName</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;popup-layout&#39;</span><span class=\"mtk1\">)\\[</span><span class=\"mtk7\">0</span><span class=\"mtk1\">\\].</span><span class=\"mtk12\">style</span><span class=\"mtk1\">.</span><span class=\"mtk12\">display</span><span class=\"mtk1\"> = </span><span class=\"mtk8\">&quot;none&quot;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}, </span><span class=\"mtk7\">5000</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;/</span><span class=\"mtk12\">script</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span></code></pre>\n<h3 id=\"3-creating-a-scroll-popup\" style=\"position:relative;\"><a href=\"#3-creating-a-scroll-popup\" aria-label=\"3 creating a scroll popup 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><strong>3. Creating a Scroll popup:</strong></h3>\n<p>This one shows up when you scroll down the page. I have set it to 500 pixels, you can change as per requirements</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"5\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;</span><span class=\"mtk12\">script</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk11\">getElementsByClassName</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;popup-layout&#39;</span><span class=\"mtk1\">)\\[</span><span class=\"mtk7\">0</span><span class=\"mtk1\">\\].</span><span class=\"mtk12\">style</span><span class=\"mtk1\">.</span><span class=\"mtk12\">display</span><span class=\"mtk1\"> = </span><span class=\"mtk8\">&quot;none&quot;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">window</span><span class=\"mtk1\">.</span><span class=\"mtk11\">onscroll</span><span class=\"mtk1\"> = </span><span class=\"mtk4\">function</span><span class=\"mtk1\"> () {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> (</span><span class=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk12\">body</span><span class=\"mtk1\">.</span><span class=\"mtk12\">scrollTop</span><span class=\"mtk1\"> &</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">; </span><span class=\"mtk7\">500</span><span class=\"mtk1\"> || </span><span class=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk12\">documentElement</span><span class=\"mtk1\">.</span><span class=\"mtk12\">scrollTop</span><span class=\"mtk1\"> &</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">; </span><span class=\"mtk7\">500</span><span class=\"mtk1\">) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk11\">getElementsByClassName</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;popup-layout&#39;</span><span class=\"mtk1\">)\\[</span><span class=\"mtk7\">0</span><span class=\"mtk1\">\\].</span><span class=\"mtk12\">style</span><span class=\"mtk1\">.</span><span class=\"mtk12\">display</span><span class=\"mtk1\"> = </span><span class=\"mtk8\">&quot;block&quot;</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 class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;/</span><span class=\"mtk12\">script</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span></code></pre>\n<h3 id=\"4-creating-a-scroll--time-5-second-popup\" style=\"position:relative;\"><a href=\"#4-creating-a-scroll--time-5-second-popup\" aria-label=\"4 creating a scroll  time 5 second popup 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><strong>4. Creating a Scroll / Time [5 second] popup:</strong></h3>\n<p>Pretty much the same as above but this one shows popup after 5 seconds of scrolling .</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"6\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;</span><span class=\"mtk12\">script</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk11\">getElementsByClassName</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;popup-layout&#39;</span><span class=\"mtk1\">)\\[</span><span class=\"mtk7\">0</span><span class=\"mtk1\">\\].</span><span class=\"mtk12\">style</span><span class=\"mtk1\">.</span><span class=\"mtk12\">display</span><span class=\"mtk1\"> = </span><span class=\"mtk8\">&quot;none&quot;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">window</span><span class=\"mtk1\">.</span><span class=\"mtk11\">onscroll</span><span class=\"mtk1\"> = </span><span class=\"mtk4\">function</span><span class=\"mtk1\"> () {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> (</span><span class=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk12\">body</span><span class=\"mtk1\">.</span><span class=\"mtk12\">scrollTop</span><span class=\"mtk1\"> &</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">; </span><span class=\"mtk7\">500</span><span class=\"mtk1\"> || </span><span class=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk12\">documentElement</span><span class=\"mtk1\">.</span><span class=\"mtk12\">scrollTop</span><span class=\"mtk1\"> &</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">; </span><span class=\"mtk7\">500</span><span class=\"mtk1\">) {</span></span>\n<span class=\"grvsc-line\"><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=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk11\">getElementsByClassName</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;popup-layout&#39;</span><span class=\"mtk1\">)\\[</span><span class=\"mtk7\">0</span><span class=\"mtk1\">\\].</span><span class=\"mtk12\">style</span><span class=\"mtk1\">.</span><span class=\"mtk12\">display</span><span class=\"mtk1\"> = </span><span class=\"mtk8\">&quot;block&quot;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">},</span><span class=\"mtk7\">5000</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=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;/</span><span class=\"mtk12\">script</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span></code></pre>\n<h3 id=\"5-creating-an-exit-popup\" style=\"position:relative;\"><a href=\"#5-creating-an-exit-popup\" aria-label=\"5 creating an exit popup 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><strong>5. Creating an Exit popup:</strong></h3>\n<p><img src=\"/c718dfa91184e4494f4d856fd051d640/Creating-an-exit-popup.gif\" alt=\"Creating an exit popup\"></p>\n<p>Only confirmation alert popup will show and you can’t make changes in html of this popup. Use following line of code on a single page.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"7\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;</span><span class=\"mtk12\">script</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">window</span><span class=\"mtk1\">.</span><span class=\"mtk11\">onbeforeunload</span><span class=\"mtk1\"> = </span><span class=\"mtk4\">function</span><span class=\"mtk1\">() {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">return</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;You are about to leave&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;/</span><span class=\"mtk12\">script</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span></code></pre>\n<p>There is another variation you can make here. In this scenario, if the user moves his cursor beyond the browser screen, you can create a popup to convince the user to stay. Below is the line of code you will need.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"8\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;</span><span class=\"mtk12\">script</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk11\">getElementsByClassName</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;popup-layout&#39;</span><span class=\"mtk1\">)\\[</span><span class=\"mtk7\">0</span><span class=\"mtk1\">\\].</span><span class=\"mtk12\">style</span><span class=\"mtk1\">.</span><span class=\"mtk12\">display</span><span class=\"mtk1\"> = </span><span class=\"mtk8\">&quot;none&quot;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk11\">addEventListener</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;mouseout&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk4\">function</span><span class=\"mtk1\"> (</span><span class=\"mtk12\">event</span><span class=\"mtk1\">) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">document</span><span class=\"mtk1\">.</span><span class=\"mtk11\">getElementsByClassName</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;popup-layout&#39;</span><span class=\"mtk1\">)\\[</span><span class=\"mtk7\">0</span><span class=\"mtk1\">\\].</span><span class=\"mtk12\">style</span><span class=\"mtk1\">.</span><span class=\"mtk12\">display</span><span class=\"mtk1\"> = </span><span class=\"mtk8\">&quot;block&quot;</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=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">lt</span><span class=\"mtk1\">;/</span><span class=\"mtk12\">script</span><span class=\"mtk1\">&</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">amp</span><span class=\"mtk1\">;</span><span class=\"mtk12\">gt</span><span class=\"mtk1\">;</span></span></code></pre>\n<p>So guys, I hope this guide helped you through various types of popups. If you love animating your pop-up, you might want to check out this tutorial of <a href=\"/animating-simple-css-popup-tutorial/\">creating an animated CSS pop-up</a>. Do try them and let us know your experiences.</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 .mtk12 { color: #9CDCFE; }\n  .dark-default-dark .mtk8 { color: #CE9178; }\n  .dark-default-dark .mtk6 { color: #D7BA7D; }\n  .dark-default-dark .mtk7 { color: #B5CEA8; }\n  .dark-default-dark .mtk11 { color: #DCDCAA; }\n  .dark-default-dark .mtk4 { color: #569CD6; }\n  .dark-default-dark .mtk15 { color: #C586C0; }\n</style>","frontmatter":{"date":"April 20, 2017","updated_date":null,"description":null,"title":"Know The Types of Website Popups and How to Create Them","tags":["CSS"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.7699115044247788,"src":"/static/d404c01e7d4da26cf8ec6404c910921c/5239a/The-Ultimate-guide-to-website-pop-ups.webp","srcSet":"/static/d404c01e7d4da26cf8ec6404c910921c/61e93/The-Ultimate-guide-to-website-pop-ups.webp 200w,\n/static/d404c01e7d4da26cf8ec6404c910921c/1f5c5/The-Ultimate-guide-to-website-pop-ups.webp 400w,\n/static/d404c01e7d4da26cf8ec6404c910921c/5239a/The-Ultimate-guide-to-website-pop-ups.webp 560w","sizes":"(max-width: 560px) 100vw, 560px"}}},"author":{"id":"Team LoginRadius","github":"LoginRadius","avatar":null}}}},{"node":{"excerpt":"JavaScript or JS helps implement complex things on web pages. Many of the developers know the importance of an minified Javascript file but…","fields":{"slug":"/engineering/16-javascript-hacks-for-optimization/"},"html":"<p>JavaScript or JS helps implement complex things on web pages. Many of the developers know the importance of an minified Javascript file but few are aware of an Optimized Javascript code.</p>\n<p>An optimized code is a combination of smartly programmed logics and small hacks to optimize performance, speed and save time.</p>\n<p>Here are sweet 16 <strong>JS hacks and tips</strong> for developers  for optimizing Javascript to improve JS performance and improve execution time without affecting server resources.</p>\n<h3 id=\"1-use-array-filter\" style=\"position:relative;\"><a href=\"#1-use-array-filter\" aria-label=\"1 use array filter 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><strong>1. Use Array Filter</strong></h3>\n<p>It is a small hack to filter out bucket of elements from the array pool. This method creates an array filled with all array elements that pass a test (provided as a function). According to requirement create a callback function for non-required elements.</p>\n<p>In below example the bucket elements are <em>null</em> and are ready to get filtered out. </p>\n<p>Example:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk12\">schema</span><span class=\"mtk1\"> = [</span><span class=\"mtk8\">&quot;hi&quot;</span><span class=\"mtk1\">,</span><span class=\"mtk8\">&quot;ihaveboyfriend&quot;</span><span class=\"mtk1\">,</span><span class=\"mtk4\">null</span><span class=\"mtk1\">, </span><span class=\"mtk4\">null</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;goodbye&quot;</span><span class=\"mtk1\">]</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">schema</span><span class=\"mtk1\"> = </span><span class=\"mtk12\">schema</span><span class=\"mtk1\">.</span><span class=\"mtk11\">filter</span><span class=\"mtk1\">(</span><span class=\"mtk4\">function</span><span class=\"mtk1\">(</span><span class=\"mtk12\">n</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\">n</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> });</span></span></code></pre>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">Output: [&quot;hi&quot;,&quot;ihaveboyfriend&quot;, &quot;goodbye&quot;]</span></code></pre>\n<p>This hack will save some time and lines of codes for developers.</p>\n<h3 id=\"2-using-string-replace-function-to-replace-all-the-values\" style=\"position:relative;\"><a href=\"#2-using-string-replace-function-to-replace-all-the-values\" aria-label=\"2 using string replace function to replace all the values 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><strong>2. Using String replace function to replace all the values</strong></h3>\n<p><em>The String.replace()</em> <em>function</em> allows you to replace strings using String and Regex.</p>\n<p>Basically this function replaces the string at its first occurrence. But to replace all using <em>replaceAll()</em> function, use <em>/g</em> at the end of a Regex:</p>\n<p>Example:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">string</span><span class=\"mtk1\"> = </span><span class=\"mtk8\">&quot;login login&quot;</span><span class=\"mtk1\">; </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">string</span><span class=\"mtk1\">.</span><span class=\"mtk11\">replace</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;in&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;out&quot;</span><span class=\"mtk1\">)); </span><span class=\"mtk3\">// &quot;logout login&quot; </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">string</span><span class=\"mtk1\">.</span><span class=\"mtk11\">replace</span><span class=\"mtk1\">(</span><span class=\"mtk5\">/in/</span><span class=\"mtk4\">g</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;out&quot;</span><span class=\"mtk1\">)); </span><span class=\"mtk3\">//&quot;logout logout&quot;</span></span></code></pre>\n<h3 id=\"3use-breakpoints-and-console-for-debugging\" style=\"position:relative;\"><a href=\"#3use-breakpoints-and-console-for-debugging\" aria-label=\"3use breakpoints and console for debugging 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><strong>3. Use breakpoints and Console for Debugging</strong></h3>\n<p>With the help of <strong>breakpoints</strong> or <strong>debugging points</strong> you can set multiple barriers to rectify source of error at every barrier. </p>\n<p><img src=\"/992c71b11d837822cbd06b34a3aa6a64/Use-breakpoints-and-Console-for-Debugging-1.webp\" alt=\"Use breakpoints and Console for Debugging\"></p>\n<p>Press F11 for next call function and f8 to resume script execution.</p>\n<p><img src=\"/b8654e35d670696359fad0c72a2cc5e2/Use-breakpoints-and-Console-for-Debugging-2.webp\" alt=\"Use breakpoints and Console for Debugging\"></p>\n<p>You can also check what dynamic values are generated by a function, using console and can check output on different values.</p>\n<h3 id=\"4-convert-to-floating-number-without-killing-performance\" style=\"position:relative;\"><a href=\"#4-convert-to-floating-number-without-killing-performance\" aria-label=\"4 convert to floating number without killing performance 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><strong>4. Convert to floating number without killing performance</strong></h3>\n<p>Often we use <strong>math.floor</strong>, <strong>math.ceil</strong> and <strong>math.round</strong> for eliminating decimals. Instead of using them <strong>use “~~”</strong> to eliminate decimals for a value.</p>\n<p>It is also helpful in increasing performance when it comes to micro optimizations in a code.</p>\n<p><strong>Example:</strong></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk12\">Use</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">~~ (</span><span class=\"mtk12\">math</span><span class=\"mtk1\">.</span><span class=\"mtk12\">random</span><span class=\"mtk1\">*</span><span class=\"mtk7\">100</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">Instead</span><span class=\"mtk1\"> </span><span class=\"mtk4\">of</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">math</span><span class=\"mtk1\">.</span><span class=\"mtk11\">round</span><span class=\"mtk1\">(</span><span class=\"mtk12\">math</span><span class=\"mtk1\">.</span><span class=\"mtk12\">random</span><span class=\"mtk1\">*</span><span class=\"mtk7\">100</span><span class=\"mtk1\">)</span></span></code></pre>\n<h3 id=\"5-using-length-to-delete-empty-in-an-array\" style=\"position:relative;\"><a href=\"#5-using-length-to-delete-empty-in-an-array\" aria-label=\"5 using length to delete empty in an array 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><strong>5. Using length to delete empty in an array</strong></h3>\n<p>This technique will help you in resizing and emptying an array.</p>\n<p>For deleting n elements in an Array, use <em><strong>array.length</strong></em>. </p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\"> </span><span class=\"mtk12\">array</span><span class=\"mtk1\">.</span><span class=\"mtk12\">length</span><span class=\"mtk1\"> = </span><span class=\"mtk12\">n</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">See</span><span class=\"mtk1\"> </span><span class=\"mtk4\">this</span><span class=\"mtk1\"> example:</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">array</span><span class=\"mtk1\"> = [</span><span class=\"mtk7\">1</span><span class=\"mtk1\">, </span><span class=\"mtk7\">2</span><span class=\"mtk1\">, </span><span class=\"mtk7\">3</span><span class=\"mtk1\">, </span><span class=\"mtk7\">4</span><span class=\"mtk1\">, </span><span class=\"mtk7\">5</span><span class=\"mtk1\">, </span><span class=\"mtk7\">6</span><span class=\"mtk1\">]; </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">array</span><span class=\"mtk1\">.</span><span class=\"mtk12\">length</span><span class=\"mtk1\">); </span><span class=\"mtk3\">// 6 </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">array</span><span class=\"mtk1\">.</span><span class=\"mtk12\">length</span><span class=\"mtk1\"> = </span><span class=\"mtk7\">3</span><span class=\"mtk1\">; </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">array</span><span class=\"mtk1\">.</span><span class=\"mtk12\">length</span><span class=\"mtk1\">); </span><span class=\"mtk3\">// 3 </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">array</span><span class=\"mtk1\">); </span><span class=\"mtk3\">// [1,2,3]</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">For</span><span class=\"mtk1\"> **</span><span class=\"mtk12\">emptying</span><span class=\"mtk1\"> </span><span class=\"mtk12\">array</span><span class=\"mtk1\">** </span><span class=\"mtk12\">use</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">array</span><span class=\"mtk1\">.</span><span class=\"mtk12\">length</span><span class=\"mtk1\"> = </span><span class=\"mtk7\">0</span><span class=\"mtk1\">;.</span></span></code></pre>\n<p><strong>Example:</strong></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"5\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">array</span><span class=\"mtk1\"> = [</span><span class=\"mtk7\">1</span><span class=\"mtk1\">, </span><span class=\"mtk7\">2</span><span class=\"mtk1\">, </span><span class=\"mtk7\">3</span><span class=\"mtk1\">, </span><span class=\"mtk7\">4</span><span class=\"mtk1\">, </span><span class=\"mtk7\">5</span><span class=\"mtk1\">, </span><span class=\"mtk7\">6</span><span class=\"mtk1\">]; </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">array</span><span class=\"mtk1\">.</span><span class=\"mtk12\">length</span><span class=\"mtk1\"> = </span><span class=\"mtk7\">0</span><span class=\"mtk1\">; </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">array</span><span class=\"mtk1\">.</span><span class=\"mtk12\">length</span><span class=\"mtk1\">); </span><span class=\"mtk3\">// 0 </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">array</span><span class=\"mtk1\">); </span><span class=\"mtk3\">// []</span></span></code></pre>\n<p>This technique is <strong>mostly preferred</strong> over any other methods to resize/unset the array elements and is one of the <strong>best javascript practices</strong> most of the developers follow.</p>\n<h3 id=\"6-merging-arrays-without-causing-server-load\" style=\"position:relative;\"><a href=\"#6-merging-arrays-without-causing-server-load\" aria-label=\"6 merging arrays without causing server load 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><strong>6. Merging arrays without causing server load</strong></h3>\n<p>If your requirement is of <strong>merging two arrays</strong>, use Array.concat() function</p>\n<p>For merging two arrays:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"6\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">array1</span><span class=\"mtk1\"> = [</span><span class=\"mtk7\">1</span><span class=\"mtk1\">, </span><span class=\"mtk7\">2</span><span class=\"mtk1\">, </span><span class=\"mtk7\">3</span><span class=\"mtk1\">]; </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">array2</span><span class=\"mtk1\"> = [</span><span class=\"mtk7\">4</span><span class=\"mtk1\">, </span><span class=\"mtk7\">5</span><span class=\"mtk1\">, </span><span class=\"mtk7\">6</span><span class=\"mtk1\">]; </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">array1</span><span class=\"mtk1\">.</span><span class=\"mtk11\">concat</span><span class=\"mtk1\">(</span><span class=\"mtk12\">array2</span><span class=\"mtk1\">)); </span><span class=\"mtk3\">// [1,2,3,4,5,6]; </span></span></code></pre>\n<p>This function works best for small arrays.</p>\n<p>To <strong>merge large arrays</strong> we use</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"7\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk10\">Array</span><span class=\"mtk1\">.</span><span class=\"mtk12\">push</span><span class=\"mtk1\">.</span><span class=\"mtk11\">apply</span><span class=\"mtk1\">(</span><span class=\"mtk12\">arr1</span><span class=\"mtk1\">, </span><span class=\"mtk12\">arr2</span><span class=\"mtk1\">)</span></span></code></pre>\n<p>Reason is using Array.concat() function on large arrays will <strong>consume lot of memory</strong> while creating a separate new array.</p>\n<p>In this case, you can use Array.push.apply(arr1, arr2) which instead will merge the second array in the first one, hence <strong>reducing the memory usage</strong>.</p>\n<p><strong>Example:</strong></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"8\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">array1</span><span class=\"mtk1\"> = [</span><span class=\"mtk7\">1</span><span class=\"mtk1\">, </span><span class=\"mtk7\">2</span><span class=\"mtk1\">, </span><span class=\"mtk7\">3</span><span class=\"mtk1\">]; </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">array2</span><span class=\"mtk1\"> = [</span><span class=\"mtk7\">4</span><span class=\"mtk1\">, </span><span class=\"mtk7\">5</span><span class=\"mtk1\">, </span><span class=\"mtk7\">6</span><span class=\"mtk1\">]; </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">array1</span><span class=\"mtk1\">.</span><span class=\"mtk12\">push</span><span class=\"mtk1\">.</span><span class=\"mtk11\">apply</span><span class=\"mtk1\">(</span><span class=\"mtk12\">array1</span><span class=\"mtk1\">, </span><span class=\"mtk12\">array2</span><span class=\"mtk1\">)); </span><span class=\"mtk3\">// [1,2,3,4,5,6];</span></span></code></pre>\n<p>It will also optimize the performance of your Javascript code irrespective of size of array.</p>\n<h3 id=\"7-use-splice-to-delete-array-elements\" style=\"position:relative;\"><a href=\"#7-use-splice-to-delete-array-elements\" aria-label=\"7 use splice to delete array elements 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><strong>7. Use splice  to delete array elements</strong></h3>\n<p>This is probably the one of the best <strong>optimization tips for javascript</strong>. It <strong>optimizes speed</strong> of your JS code.</p>\n<p>Using splice instead of delete is a good practice, it will save some”null/undefined space” in your code.</p>\n<p>The downside of <strong>using delete</strong> is it will delete the object property, but will <strong>not reindex the array</strong> or update its length, leaving undefined values. Also it consumes a-lot of time in execution.</p>\n<p>Using <em>splice</em></p>\n<p>Example</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"9\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk12\">myArray</span><span class=\"mtk1\"> = [</span><span class=\"mtk8\">&quot;a&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;b&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;c&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;d&quot;</span><span class=\"mtk1\">] </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">myArray</span><span class=\"mtk1\">.</span><span class=\"mtk11\">splice</span><span class=\"mtk1\">(</span><span class=\"mtk7\">0</span><span class=\"mtk1\">, </span><span class=\"mtk7\">2</span><span class=\"mtk1\">) [</span><span class=\"mtk8\">&quot;a&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;b&quot;</span><span class=\"mtk1\">]</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">Result: </span><span class=\"mtk12\">myArray</span><span class=\"mtk1\"> [</span><span class=\"mtk8\">&quot;c&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&quot;d&quot;</span><span class=\"mtk1\">]</span></span></code></pre>\n<h3 id=\"8-checking-values-in-an-object\" style=\"position:relative;\"><a href=\"#8-checking-values-in-an-object\" aria-label=\"8 checking values in an 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><strong>8. Checking values in an Object</strong></h3>\n<p>To check whether an object is empty or not,  use</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"10\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk10\">Object</span><span class=\"mtk1\">.</span><span class=\"mtk11\">keys</span><span class=\"mtk1\">(</span><span class=\"mtk12\">YOUR</span><span class=\"mtk1\">\\</span><span class=\"mtk12\">_OBJECT</span><span class=\"mtk1\">).</span><span class=\"mtk12\">length</span><span class=\"mtk1\"> </span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">// 0 returns if object is empty</span></span></code></pre>\n<p>Following code return the number of elements in an Object.</p>\n<h3 id=\"9-cache-the-variable\" style=\"position:relative;\"><a href=\"#9-cache-the-variable\" aria-label=\"9 cache the variable 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><strong>9. Cache the variable</strong></h3>\n<p>Caching the variable tremendously <strong>increase javascript performance</strong>.</p>\n<p>Everytime we use document.getElementById() or getElementsByClassName(), JS travels through all elements repeatedly upon each similar element request.</p>\n<p>In Order to boost performance, <strong>cache your selections</strong> to some variable (if using the same selection multiple times).</p>\n<p><strong>Example:</strong></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"11\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">cached</span><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\">&#39;someElement&#39;</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">cached</span><span class=\"mtk1\">.</span><span class=\"mtk11\">addClass</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;cached-element&#39;</span><span class=\"mtk1\">);</span></span></code></pre>\n<p>It is a simple <strong>optimization tip</strong> with drastic impact on performance, recommended for <strong>processing large arrays in loop(s)</strong>.</p>\n<p>Check this <a href=\"http://jquery-howto.blogspot.in/2008/12/caching-in-jquery.html\">link</a> for performance results.</p>\n<h3 id=\"10-use-switch-case-instead-of-ifelse\" style=\"position:relative;\"><a href=\"#10-use-switch-case-instead-of-ifelse\" aria-label=\"10 use switch case instead of ifelse 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><strong>10. Use switch case instead of if/else</strong></h3>\n<p>Generally switch cases are used over if/else statements to <strong>perform almost the same tasks</strong>.</p>\n<p>The fact that in switch statements  expression to test is only evaluated once, execution time becomes less for the script compared to if/else where for every if , it has to be evaluated.</p>\n<h3 id=\"11-short-circuits-conditionals\" style=\"position:relative;\"><a href=\"#11-short-circuits-conditionals\" aria-label=\"11 short circuits conditionals 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><strong>11. Short-circuits conditionals</strong></h3>\n<p>Short circuiting  is when a logical operator doesn't evaluate all its arguments.</p>\n<p>The code</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"12\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> (</span><span class=\"mtk12\">loggedin</span><span class=\"mtk1\">) { </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">welcome</span><span class=\"mtk1\">\\</span><span class=\"mtk11\">_messege</span><span class=\"mtk1\">();</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> }</span></span></code></pre>\n<p>Make it short by using combination of a verified variable and a function using <em>&#x26;&#x26;</em> (AND operator) in between both.</p>\n<p> Now above code can be made in one line</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"13\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk12\">loggedin</span><span class=\"mtk1\"> && </span><span class=\"mtk12\">welcome</span><span class=\"mtk1\">\\</span><span class=\"mtk11\">_messege</span><span class=\"mtk1\">();</span></span></code></pre>\n<h3 id=\"12-getting-the-last-item-in-the-array\" style=\"position:relative;\"><a href=\"#12-getting-the-last-item-in-the-array\" aria-label=\"12 getting the last item in the array 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><strong>12. Getting the last item in the array</strong></h3>\n<p><em>Array.prototype.slice(begin, end)</em> is used to cut arrays when you set the start and end arguments.  But if you don't set the end argument, this function will automatically set the max value for the array.</p>\n<p>A smart hack is it can also accept negative values and by setting a negative number as begin argument, you will get the last elements from the array.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"14\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">array</span><span class=\"mtk1\"> = [</span><span class=\"mtk7\">1</span><span class=\"mtk1\">, </span><span class=\"mtk7\">2</span><span class=\"mtk1\">, </span><span class=\"mtk7\">3</span><span class=\"mtk1\">, </span><span class=\"mtk7\">4</span><span class=\"mtk1\">, </span><span class=\"mtk7\">5</span><span class=\"mtk1\">, </span><span class=\"mtk7\">6</span><span class=\"mtk1\">]; </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">array</span><span class=\"mtk1\">.</span><span class=\"mtk11\">slice</span><span class=\"mtk1\">(-</span><span class=\"mtk7\">1</span><span class=\"mtk1\">)); </span><span class=\"mtk3\">// [6] </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">array</span><span class=\"mtk1\">.</span><span class=\"mtk11\">slice</span><span class=\"mtk1\">(-</span><span class=\"mtk7\">2</span><span class=\"mtk1\">)); </span><span class=\"mtk3\">// [5,6] </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">array</span><span class=\"mtk1\">.</span><span class=\"mtk11\">slice</span><span class=\"mtk1\">(-</span><span class=\"mtk7\">3</span><span class=\"mtk1\">)); </span><span class=\"mtk3\">// [4,5,6]</span></span></code></pre>\n<h3 id=\"13-default-values-using--operator\" style=\"position:relative;\"><a href=\"#13-default-values-using--operator\" aria-label=\"13 default values using  operator 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><strong>13. Default values using || operator</strong></h3>\n<p>In JS there is a basic rule of having a default value otherwise process will halt at undefined values.</p>\n<p>To provide default value in a variable use || to stay away from this most common issue.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"js\" data-index=\"15\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">a</span><span class=\"mtk1\"> = </span><span class=\"mtk12\">a</span><span class=\"mtk1\"> || </span><span class=\"mtk8\">&#39;hello&#39;</span></span></code></pre>\n<p>The developer must check whether there are any conflicting values that might be passed to the function to avoid Bugs.</p>\n<h3 id=\"14-beautifying-js-code\" style=\"position:relative;\"><a href=\"#14-beautifying-js-code\" aria-label=\"14 beautifying js code 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><strong>14. Beautifying JS code</strong></h3>\n<p>For beautifying your Javascript  code use <a href=\"http://jsbeautifier.org/\">jsbeautifier</a>. It formats a clumsy JS code into well structured code.</p>\n<p><strong>Code before Beautifying</strong></p>\n<p><img src=\"/ffb7a1c2536dd770e56424c03482dcb5/Beautifying-JS-code-2.webp\" alt=\"Beautifying JS code 1\"></p>\n<p><strong>Code after Beautifying</strong></p>\n<p><img src=\"/e10fa72828d50c5d23c2b68009ba432e/Beautifying-JS-code-1.webp\" alt=\"Beautifying JS code 2\"></p>\n<h3 id=\"15-checking-js-performance\" style=\"position:relative;\"><a href=\"#15-checking-js-performance\" aria-label=\"15 checking js performance 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><strong>15. Checking JS Performance</strong></h3>\n<p>To check how well a Javascript code is performing and share results use jsperf. It is easiest way to create and share testcases.</p>\n<h3 id=\"16-online-javascript-editor\" style=\"position:relative;\"><a href=\"#16-online-javascript-editor\" aria-label=\"16 online javascript editor 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><strong>16. Online javascript editor</strong></h3>\n<p><a href=\"http://jsfiddle.net/\">Jsfiddle</a> and <a href=\"http://jsbin.com/\">jsbin</a> is a tool for experimenting with your Javascript code and other web languages.</p>\n<p>It is also a code sharing site. As you type into one of the editor panels the output is generated in real-time in the output panel.</p>\n<p>These are some useful hacks and tips for optimizing javascript performance. It is not mandatory to use them all the time because cases and conditions will vary. If you have tricks other than these, do share with us in comment section.</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 .mtk12 { color: #9CDCFE; }\n  .dark-default-dark .mtk1 { color: #D4D4D4; }\n  .dark-default-dark .mtk8 { color: #CE9178; }\n  .dark-default-dark .mtk4 { color: #569CD6; }\n  .dark-default-dark .mtk11 { color: #DCDCAA; }\n  .dark-default-dark .mtk15 { color: #C586C0; }\n  .dark-default-dark .mtk10 { color: #4EC9B0; }\n  .dark-default-dark .mtk3 { color: #6A9955; }\n  .dark-default-dark .mtk5 { color: #D16969; }\n  .dark-default-dark .mtk7 { color: #B5CEA8; }\n</style>","frontmatter":{"date":"April 07, 2017","updated_date":null,"description":"Learn how to optimize performance using some useful javascript hacks, tips and tricks.","title":"Javascript tips and tricks to Optimize Performance","tags":["Engineering","JavaScript","Hacks","Array"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.3793103448275863,"src":"/static/0d6472e55ba0b111b3dfa895ec2dec57/7f8e9/16-JavaScript-Hacks-to-save-time-and-boost-productivity-768x555.webp","srcSet":"/static/0d6472e55ba0b111b3dfa895ec2dec57/61e93/16-JavaScript-Hacks-to-save-time-and-boost-productivity-768x555.webp 200w,\n/static/0d6472e55ba0b111b3dfa895ec2dec57/1f5c5/16-JavaScript-Hacks-to-save-time-and-boost-productivity-768x555.webp 400w,\n/static/0d6472e55ba0b111b3dfa895ec2dec57/7f8e9/16-JavaScript-Hacks-to-save-time-and-boost-productivity-768x555.webp 768w","sizes":"(max-width: 768px) 100vw, 768px"}}},"author":{"id":"Team LoginRadius","github":"LoginRadius","avatar":null}}}},{"node":{"excerpt":"Gone are the days when learning coding or programming was reserved for the geeks or nerds. The case is exactly different nowadays. The…","fields":{"slug":"/engineering/learn-to-code-using-10-websites/"},"html":"<p>Gone are the days when learning coding or programming was reserved for the geeks or nerds. The case is exactly different nowadays. The latest buzz of “How to code” is here to stay. Making sure that you have little coding knowledge under your belt is proving to be an incredible skill no matter whether you are a marketer or an entrepreneur or a member of any of business team. Talk to any entrepreneur, marketer or freelancer, you will get an idea about learning coding will help you get through. The reasons are more than one! Half of the 2016 is gone, so if you haven’t included this incredible skill in your 2017’s new year resolution, you need to reconsider. Here is why!</p>\n<h3 id=\"why\" style=\"position:relative;\"><a href=\"#why\" aria-label=\"why 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><strong>Why?</strong></h3>\n<p>With softwares ruling the digital world, the demand of learning coding is becoming must for every professionals in every field whether it is marketing, technology, commerce, finance and what not. As the digital age is making us more and more dependant on computer softwares for business, learning to code has become helpful here. Learn to code is already in the must have technical skills list of 21st century and this demand of technical skills is growing like never before.</p>\n<p>Coding is problem solving. Coding is no different than the way you can fuel up your car, check the oil and get it serviced by reading the manual you are provided with. But coding takes you a long way ahead. It is beyond these simple things. It teaches you to repaint your car, customize the engine to make it work in the way you want. Hope you got an idea why coding is important and why you should also learn it.</p>\n<h3 id=\"you-are-convinced-now-what\" style=\"position:relative;\"><a href=\"#you-are-convinced-now-what\" aria-label=\"you are convinced now what 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><strong>You are convinced! Now what?</strong></h3>\n<ul>\n<li>Did you know Bill Gates, got into programming at a very early age? The reason being his prep school used to provide students access to GE Mainframe Computer.</li>\n<li>Similarly the owner of Facebook, Mark Zuckerberg, hired a private programming tutor to learn the same while growing up.</li>\n</ul>\n<p>Yeah, yeah, I know this coding thing is not the only factor behind their success (or should I say making them billionaire), but it didn’t hurt either.</p>\n<p>But unlike them, most of us were not gifted with this kind of exposure to the digital world and most of us are still naive to how the world of programming works. Many of the people around are still wondering how to write and combine the long string of code to create a beautiful website, app and more! And trust me you are not alone!</p>\n<p>But don’t worry because with so many information available online, you can also master the same. No need to spend a lot of money or put yourself in debt in coding learning, as these resources are definitely going to help you to get through this.</p>\n<h3 id=\"10-handful-resources-to-make-the-process-of-learning-coding-easier\" style=\"position:relative;\"><a href=\"#10-handful-resources-to-make-the-process-of-learning-coding-easier\" aria-label=\"10 handful resources to make the process of learning coding easier 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><strong>10 handful resources to make the process of learning coding easier!</strong></h3>\n<h4 id=\"1codecademy-\" style=\"position:relative;\"><a href=\"#1codecademy-\" aria-label=\"1codecademy  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><strong>1. <a href=\"https://www.codecademy.com/\">Codecademy</a></strong> <strong>:</strong></h4>\n<p><strong>Price</strong> - Free but pro-version also available at $19.99/moPro for $19.99/moPro for $19.99/mo</p>\n<p>Codecademy - Teaching the world how to code, definitely tops my list while talking about the top resources for how to learn programming. Currently owning around 25 million users, one can start learning as soon as he registers himself on the website. They can learn to design websites with HTML, CSS and also customize it with Javascript.</p>\n<p>The courses provided are not lecture style but the students actually get to do hands on coding and witness changes real time. Sims, the owner of Codecademy says that the website allows students to learn the coding by providing preview for every line they write immediately instead of watching an instructor. Apart from that, Codecademy also provides students access to QnA forums and groups to learn on topics like Python, Ruby on Rails, Etsy, etc.</p>\n<p><strong>2. <a href=\"https://www.w3schools.com/\">W3schools</a></strong> <strong>:</strong></p>\n<p><strong>Price</strong> : Free</p>\n<p>W3schools - the largest web developer site, as they define it, provides free tutorials on JavaScript, HTML, CSS, jQuery and what not along with lot of references. So if you want to know what <div> means, it will quickly show up that “<div> defines a division or section in HTML document.”</p>\n<h4 id=\"3tuts-\" style=\"position:relative;\"><a href=\"#3tuts-\" aria-label=\"3tuts  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><strong>3. <a href=\"https://tutsplus.com/\">Tuts+</a></strong> <strong>:</strong></h4>\n<h4 id=\"price--15mo-and-pro-version-at-360year\" style=\"position:relative;\"><a href=\"#price--15mo-and-pro-version-at-360year\" aria-label=\"price  15mo and pro version at 360year 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><strong>Price</strong> : $15/mo and pro version at $360/year</h4>\n<p>The website provides tiered subscription plan that allows users to download multiple ebooks too along with the course. The ebook comprises of a huge catalog that comes with different code specifics like Jekyll, Sass, SVG, etc. I should definitely not forget to mention that even professionals can take the ongoing education courses to brush up their programming skills. The website provides learner tutorials in the form of write-ups about various topics.</p>\n<p><strong>Price</strong> : Free but pro version available at $29/mo</p>\n<p>The famous e-learning course provider offers a wide range of courses in several types of programming languages, web tools and designing. The website offers both free as well as paid versions. With free version users can get access to the 10 introductory courses that include topics like SQL, Objective C, jQuery which are great for getting started. While with the paid version, users can get access to 200 videos and 50+ interesting courses. The website basically works on learn, practice, win and track model which means first the users can learn via watching videos and then challenges are placed in front of them to track their learning experience.</p>\n<h4 id=\"5khan-academy-\" style=\"position:relative;\"><a href=\"#5khan-academy-\" aria-label=\"5khan academy  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><strong>5. <a href=\"https://www.khanacademy.org/\">Khan Academy</a></strong> <strong>:</strong></h4>\n<p><strong>Price</strong> : Free</p>\n<p>The academy is best for those who prefer short videos to learn things. Started in 2006, by Salman Khan, the idea of this website was generated after creating and sharing video tutorials on Youtube. One of the original e-courses providers, the Khan Academy has become widely popular over the years and offers courses in numerous programming languages, both for beginners as well as experts. Relying heavily on videos, users can learn to code animations, games, drawings and a lot more. For those who are planning to start their coding career, or are beginners at coding, the Khan Academy is the best place.</p>\n<h4 id=\"6treehouse-\" style=\"position:relative;\"><a href=\"#6treehouse-\" aria-label=\"6treehouse  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><strong>6. <a href=\"https://teamtreehouse.com/\">Treehouse</a></strong> <strong>:</strong></h4>\n<p><strong>Price</strong> : Free trial for 2 weeks, Basic version at $25/mo and pro version at $50/mo</p>\n<p>The online technology courses provider, Treehouse provides programming courses for both beginners as well as experts. The website works on learn, practice and earn model. With 222+ courses, videos, challenges, the website makes sure that the learners are kept busy. Apart from that, it also helps you learn new business strategies to make the best out of your knowledge. But unlike above mentioned options, for this one, you need to spend some cash before you go ahead. The basic version comes at $25/mo with which you get access to around 1000+ videos and can take interesting challenges. While if you go for the pro version at around $50/mo users can unlock the bonus content and download videos to watch offline too.</p>\n<h4 id=\"7codeorg-\" style=\"position:relative;\"><a href=\"#7codeorg-\" aria-label=\"7codeorg  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><strong>7. <a href=\"https://code.org/\">Code.org</a></strong> <strong>:</strong></h4>\n<p><strong>Price</strong> : Free</p>\n<p>Another player in the field of online coding courses, the website’s mission is to provide more and more people opportunity to learn programming. The website works more like games with drag &#x26; drop tiles. Learners can see the code both during challenge as well as when it is completed.</p>\n<p>The next three in the list are massive open online courses provider ie MOOC. These websites provide courses related to not only coding but other fields too like life science, engineering, health habits, etc.</p>\n<h4 id=\"8coursera-\" style=\"position:relative;\"><a href=\"#8coursera-\" aria-label=\"8coursera  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><strong>8. <a href=\"https://www.coursera.org/\">Coursera</a></strong> <strong>:</strong></h4>\n<p><strong>Price</strong> : Both free and paid</p>\n<p>Despite of being founded just 4 years ago, Coursera has become a major Major Open Online Courses provider that offers around 1990 courses from 119 well known institutions. Though there are certain programs that require you to spend money to get certified, there are hundred of other free introductory courses that provide specializations from well known universities like University of Toronto and Vanderbilt, etc. One of the widely popular MOOCs provided by Coursera is “<a href=\"https://www.coursera.org/learn/python\">Programming for everybody (Getting started with Python)</a></p>\n<h4 id=\"9udemy-\" style=\"position:relative;\"><a href=\"#9udemy-\" aria-label=\"9udemy  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><strong>9. <a href=\"https://www.udemy.com/\">Udemy</a></strong> <strong>:</strong></h4>\n<p><strong>Price</strong> : Free to hundreds of dollars</p>\n<p>Another MOOC provider, Udemy is one place you can find resources for just anything. It is a great place to develop your coding skills with courses like <a href=\"https://www.udemy.com/java-the-complete-java-developer-course/\">Complete Java Developer Course</a>. Though the courses fee varies from free to hundreds of dollars, Udemy has created its own position when it comes to learning programming<strong>.</strong> Another feature that it brings along is to allow user to sign up as an instructor and create his/her own course.</p>\n<h4 id=\"10edx-\" style=\"position:relative;\"><a href=\"#10edx-\" aria-label=\"10edx  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><strong>10. <a href=\"https://www.edx.org/\">edX</a></strong> <strong>:</strong></h4>\n<p><strong>Price</strong> : Free</p>\n<p>Similar to above, this one is also a MOOC provider, serving millions of students around the globe. But this one is a non profit and open source which means anyone can build his own tools and contribute to the edX platform. Some of the most popular edX course is “Fundamentals of Computer Science” by IIT Bombay. Most of the courses I found here were free, but to get a verified certificate you need to spend some cash which differs between the type of courses you are enrolled with.</p>\n<p>Though there are hundreds of other websites that help you to enhance your coding skills, these are the top ten sites I found to be the best. Have you tried any of these? How was your experience? I would love to know about it in the comments below.</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":"October 21, 2016","updated_date":null,"description":null,"title":"Learn How To Code Using The 10 Cool Websites","tags":["Courses","Learning Websites"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.3605442176870748,"src":"/static/984ce3cc0d4c43ee0925e08cc7b336fc/403a4/How-to-code-using-the-10-cool-websites-768x564-300x220.webp","srcSet":"/static/984ce3cc0d4c43ee0925e08cc7b336fc/61e93/How-to-code-using-the-10-cool-websites-768x564-300x220.webp 200w,\n/static/984ce3cc0d4c43ee0925e08cc7b336fc/403a4/How-to-code-using-the-10-cool-websites-768x564-300x220.webp 300w","sizes":"(max-width: 300px) 100vw, 300px"}}},"author":{"id":"Team LoginRadius","github":"LoginRadius","avatar":null}}}},{"node":{"excerpt":"Many of the developers believe that they are immune to the need of marketing/branding themselves. As a developer your job is to create…","fields":{"slug":"/engineering/personal-branding-for-developers/"},"html":"<p>Many of the developers believe that they are immune to the need of marketing/branding themselves. As a developer your job is to create ultimate applications, right? After all you are not a celebrity or some rockstar! But isn’t it better to be in demand for fruitful consultations, speaking and writing? Well, all this is possible if you are able to create a personal brand!</p>\n<p>In this article I am going to focus on why as a developer you should focus on personal branding, how it is going to help your job and career and finally, will guide you on how you can also create a personal brand. First thing first, let’s start with what is personal branding.</p>\n<p><strong>What is personal branding?</strong></p>\n<p><img src=\"/19a1cce232eecdc839a68b902e3eb968/Apple-logo-248x300.webp\" alt=\"Apple Logo\">Do you recognize this logo? Well, Of course  you do! But have you ever wondered how come you recognized this logo without even a name? Well, you recognized it because the brand is so strong that without even a proper title, you are able to recognize it and that’s what branding do.</p>\n<p>The concept of personal branding is quite similar to that of company branding. Personal branding is all about thinking yourself as a brand. It is about showing people who you are and what is your passion. When you think about some specific programming language, your mind goes back to some specific names associated with that language, who are either the father of that language or have done some amazing work in that field, right?</p>\n<p>To get the more clear idea, here is what <a href=\"http://www.paulirish.com/\">Paul Irish</a>, the front end developer of Google Chrome team, has to say on the concept of personal branding - </p>\n<p><em>“Personal branding is the art of consistently presenting, online and offline, the essence of how you stand out from the crowd.”</em></p>\n<p>Personal branding is all about you and only you :  </p>\n<ul>\n<li>who you are</li>\n<li>what are you passionate about</li>\n<li>who you wanna be</li>\n<li>how would you like to be seen</li>\n<li>how actually people see you</li>\n<li>what you do and what you did</li>\n<li>what you know and what you don’t</li>\n<li>what you like to share</li>\n</ul>\n<p>and more! Personal branding is basically about everything that defines you from the languages you are expertize to the blogs you write.</p>\n<p><strong>Why you should focus on personal branding?</strong></p>\n<p>Personal branding is no longer an option, but it has become crucial for everyone. After all we are living in the digital world where it is simpler to reach to the next level. So it’s not exactly about being the rockstar but maybe it is. May be it is about becoming popular! May be it is about getting that power. Here I am presenting you three key reasons why personal branding is important for you-</p>\n<ol>\n<li><strong>You are not crucial!</strong><br>\nC’mon, no matter how rude that sounds, but you know it is true. The competition is increasing day by day and you know, there are millions of others waiting out there to take your place. So yeah, face it, YOU ARE NOT CRUCIAL! and this gives you one of the key reason to try your hand in personal branding. Let people know what you do and why you are better than others..</li>\n<li>\n<p><strong>No job is permanent!</strong>  </p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">Another harsh reality! No matter how much your company loves you but you know no job is forever. So be prepared! You don’t know when the situation changes. As a developer personal branding matters when you are looking to change your job. You want your employers to hire you not only as a good developer but also as an innovative leader. To make that possible, you need to cultivate a personal brand that can highlight your value to your potential employers.</span></code></pre>\n</li>\n<li>\n<p><strong>Sky's the limit!</strong>  </p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">The process of learning has no end. While creating personal brand, you meet many people from your niche. You interact with them, share your knowledge, learn from them, discuss ideas and all this will give you the level of expertise that wouldn’t have been possible otherwise. Doesn’t matter how you want to improve your career, personal branding is the key!</span></code></pre>\n</li>\n</ol>\n<p><strong>How to manage your personal brand?</strong></p>\n<p>As a developer, breaking through the glass ceiling demands much more than excellent programming skills. Cultivating a strong personal brand can really help you out. GET VISIBILITY is all I want to say!</p>\n<p>You might have the best expertise in certain technology, you might have designed an amazing product but all this is meaningless if nobody can see you. Here are some tips on how you can get visibility :</p>\n<ol>\n<li>\n<p><strong>Try your hand at blogging :</strong><br>\nBlogging is an amazing way to tell people who you are. Blog about anything you hold expertize in, whether it is a programming language or it is some kind of technology, let people understand who you actually are. There are many developers out there who have some awesome technical blogs where they share their knowledge and write about their specialities.For inspiration you can have a look at the blog of <a href=\"http://ejohn.org/\">John Resig</a>, the creator and founder of jQuery. Another tech blog champion is Scott Hanselman. Make sure to have a look on his popular blogs <a href=\"http://www.hanselman.com\">www.hanselman.com</a>, <a href=\"http://hanselminutes.com/\">hanselminutes</a>, etc.  </p>\n<p><img src=\"/0f8f0de8ed9264985c39b11fc2110b33/blogging-for-personal-branding.webp\" alt=\"blogging for personal branding\">Stick to one topic, you are best at and select the blogging platform that suits you like Wordpress, Tumblr, Blogspot, etc. Post informative content on regular basis and soon you will have a huge audience waiting for your content and engaging with you. Posting two to three informative blog is enough to keep you in demand. Also there are some specific sites like<a href=\"http://www.asp.net\">www.asp.net</a> where you can submit articles to gain immense popularity.</p>\n</li>\n<li>\n<p><strong>Embrace Social Media :</strong>  </p>\n<p>You might have heard that Facebook and Twitter are all about wasting time, but let me tell you this is not at all true. Social media provides you a great opportunity to build networks. It is must to get visibility on various social media networks if you want to be found by people who share same niche as you.<br>\n<img src=\"/0bcf08775ca2ce3cfb3bb8dcc35e5bc2/Social-media-for-personal-branding.webp\" alt=\"social media for personal branding\"><br>\nThere are various ways how you can track your brand on social media. My personal favorite is Google Alert which notifies whenever people are talking about me or my projects. While some times they are talking about the work I have done, sometimes they also complaint which helps me understand where I am wrong. There are many others, like on Twitter, you can use <a href=\"https://tweetdeck.twitter.com/\">Tweetdeck</a> . Apart from that, create a strong persona on Linkedin, Facebook, Google+, etc. Interact with people, reply to their queries and become social media champion.<br>\nSome popular developers who are social media champions as well include <a href=\"https://twitter.com/shanselman\">Scott Hanselman</a>, <a href=\"https://www.linkedin.com/in/jeresig\">John Resig</a>, etc  </p>\n</li>\n<li>\n<p><strong>Participate in Communities:</strong>  </p>\n<p>Communities like Quora, Stackoverflow, Warrior Forum, etc can be your best friends if you are intending to create brand online. Join these communities and try your best to solve the queries of users from your niche. It will not only help you interact your kind of people but will also improve your problem solving skills. Sites like Stack Overflow, GitHub allow users to work together on projects, that can open a wide opportunity to learn.  </p>\n</li>\n<li>\n<p><strong>Contribute to Open source or start Open source :</strong>  </p>\n<p>Another great way to cultivate personal brand is to contribute to open source or start open source. While contributing to an open source can be an amazing experience it will earn you recognition among your fellow community. Also you can start open source. If you are getting difficulties to start open source, have a look at this interesting <a href=\"https://opensource.guide/how-to-contribute/\">article</a>.</p>\n</li>\n</ol>\n<p><strong>What I’m trying to say is</strong></p>\n<p>Maybe you don’t want to become a rockstar developer or you are happy with your current job, but still there is a huge difference between doing the job and doing the job in excellent way. After all, you have worked hard to be where you are today and you deserve to get recognized for it. So why tomorrow, start now and reach the next step.</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</style>","frontmatter":{"date":"September 23, 2016","updated_date":null,"description":null,"title":"Personal Branding For Developers: Why and How?","tags":["Branding"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1,"src":"/static/cb6590bb3c439f5b33ab6c250865863c/e7487/Personal-Branding-For-Developers-150x150.webp","srcSet":"/static/cb6590bb3c439f5b33ab6c250865863c/e7487/Personal-Branding-For-Developers-150x150.webp 150w","sizes":"(max-width: 150px) 100vw, 150px"}}},"author":{"id":"Sreekant","github":null,"avatar":null}}}},{"node":{"excerpt":"I often come across people and clients who would like to build their custom login, registration, and lost password form in WordPress instead…","fields":{"slug":"/engineering/wordpress-custom-login-form-part-1/"},"html":"<p>I often come across people and clients who would like to build their custom login, registration, and lost password form in WordPress instead of using the default wp-login.php page. It's probably because it's too wordpress-y.</p>\n<p>In this tutorial, I will demonstrate how to build a custom login form using the default functionality that wordpress gives us.</p>\n<ul>\n<li><a href=\"#buildlogin\">Building a Custom Login Form</a></li>\n<li><a href=\"#loginresponse\">Handling the Login Form Response</a></li>\n</ul>\n<h2 id=\"building-a-wordpress-login-form-out-of-the-box\" style=\"position:relative;\"><a href=\"#building-a-wordpress-login-form-out-of-the-box\" aria-label=\"building a wordpress login form out of the box 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>Building a WordPress Login Form (Out of the box)</h2>\n<p>This is what WordPress gives us out of the box.</p>\n<p><img src=\"/4992e4990e00d35677ba5119762882c4/wp-login.webp\" alt=\"wp-login\"><br>\nThere are quite a few different options available to make a custom login page. You can build a <a href=\"https://codex.wordpress.org/Shortcode_API\">shortcode</a> so that you could simply put [wp-login] or something you like on any page/post, make a page theme file and use that page to attach to a post/page, a widget could be a good solution too, or maybe you'd like to simply edit the existing form and add some pizzazz to it.</p>\n<p>I am going to show you all of this tutorial using the page-theme method because it is probably the easiest to implement for beginners. This will also give you an intro into page themes, if your not familiar with it.</p>\n<p>To start our theme, you will need to do the following:</p>\n<ol>\n<li>Install WordPress</li>\n<li>Navigate to your <em>wp-content/themes</em> folder and choose a theme to edit or install a new one</li>\n<li>create a file called <em>page-login.php</em> in the theme directory</li>\n<li>Next open that file with a text editor of your choosing and add the following at the top of the php file.</li>\n</ol>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"php\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;?php</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">/*</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">Template Name: Login</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">*/</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk11\">get_header</span><span class=\"mtk1\">(); ?</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;div id=</span><span class=\"mtk8\">&quot;primary&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk4\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;content-area&quot;</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;div id=</span><span class=\"mtk8\">&quot;content&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk4\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;site-content&quot;</span><span class=\"mtk1\"> role=</span><span class=\"mtk8\">&quot;main&quot;</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;/div</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;!-- </span><span class=\"mtk3\">#content --&amp;amp;amp;gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;/div</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;!-- </span><span class=\"mtk3\">#primary --&amp;amp;amp;gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;?php </span><span class=\"mtk11\">get_sidebar</span><span class=\"mtk1\">(); ?</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;?php </span><span class=\"mtk11\">get_footer</span><span class=\"mtk1\">(); ?</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;</span></span></code></pre>\n<p>To initialize this page template, make sure to activate the theme you've selected in \"Appearance/Themes\" in your admin dashboard and then navigate to a page or post. On the right hand side of your page/post editor you should now see a dropdown available for template under \"Page Attributes\". Change your template to \"Login\" or to the name that you specified in \"Template Name:\" and that will attach that page theme to this page/post.</p>\n<p>Now we're ready to start editing this page-login.php template file. So first open this file in your favorite editor and Let's get a login page started.</p>\n<p>To quickly show you how to get this login on the page Let's paste the following code between the div with id of content.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"php\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;div id=</span><span class=\"mtk8\">&quot;primary&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk4\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;content-area&quot;</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;div id=</span><span class=\"mtk8\">&quot;content&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk4\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;site-content&quot;</span><span class=\"mtk1\"> role=</span><span class=\"mtk8\">&quot;main&quot;</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;?php </span><span class=\"mtk11\">wp_login_form</span><span class=\"mtk1\">(); ?</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;/div</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;!-- </span><span class=\"mtk3\">#content --&amp;amp;amp;gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;/div</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;!-- </span><span class=\"mtk3\">#primary --&amp;amp;amp;gt;</span></span></code></pre>\n<p>Look at what that small piece of code do</p>\n<p><img src=\"/e55ab397626a02a30c4277d670ff7f89/custom-login.webp\" alt=\"custom-login\"></p>\n<p>Now we need to set some arguments that we can provide to this form to customize it. Let's take a look at the documentation for <a href=\"https://developer.wordpress.org/reference/functions/wp_login_form/\">wp<em>login</em>form()</a></p>\n<p>In that document, it explains all the uses and arguments of wp<em>login</em>form(). Let's use those arguments section and see what happens. Paste the $args section shown in the wordpress doc right above our login form.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"php\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;?php </span><span class=\"mtk12\">$args</span><span class=\"mtk1\"> = </span><span class=\"mtk11\">array</span><span class=\"mtk1\">(</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">&#39;echo&#39;</span><span class=\"mtk1\"> =</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt; </span><span class=\"mtk4\">true</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">&#39;redirect&#39;</span><span class=\"mtk1\"> =</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt; ( </span><span class=\"mtk11\">is_ssl</span><span class=\"mtk1\">() ? </span><span class=\"mtk8\">&#39;https://&#39;</span><span class=\"mtk1\"> : </span><span class=\"mtk8\">&#39;http://&#39;</span><span class=\"mtk1\"> ) . </span><span class=\"mtk12\">$_SERVER</span><span class=\"mtk1\">[</span><span class=\"mtk8\">&#39;HTTP_HOST&#39;</span><span class=\"mtk1\">] . </span><span class=\"mtk12\">$_SERVER</span><span class=\"mtk1\">[</span><span class=\"mtk8\">&#39;REQUEST_URI&#39;</span><span class=\"mtk1\">],</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">&#39;form_id&#39;</span><span class=\"mtk1\"> =</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt; </span><span class=\"mtk8\">&#39;loginform&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">&#39;label_username&#39;</span><span class=\"mtk1\"> =</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt; </span><span class=\"mtk11\">__</span><span class=\"mtk1\">( </span><span class=\"mtk8\">&#39;Username&#39;</span><span class=\"mtk1\"> ),</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">&#39;label_password&#39;</span><span class=\"mtk1\"> =</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt; </span><span class=\"mtk11\">__</span><span class=\"mtk1\">( </span><span class=\"mtk8\">&#39;Password&#39;</span><span class=\"mtk1\"> ),</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">&#39;label_remember&#39;</span><span class=\"mtk1\"> =</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt; </span><span class=\"mtk11\">__</span><span class=\"mtk1\">( </span><span class=\"mtk8\">&#39;Remember Me&#39;</span><span class=\"mtk1\"> ),</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">&#39;label_log_in&#39;</span><span class=\"mtk1\"> =</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt; </span><span class=\"mtk11\">__</span><span class=\"mtk1\">( </span><span class=\"mtk8\">&#39;Log In&#39;</span><span class=\"mtk1\"> ),</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">&#39;id_username&#39;</span><span class=\"mtk1\"> =</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt; </span><span class=\"mtk8\">&#39;user_login&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">&#39;id_password&#39;</span><span class=\"mtk1\"> =</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt; </span><span class=\"mtk8\">&#39;user_pass&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">&#39;id_remember&#39;</span><span class=\"mtk1\"> =</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt; </span><span class=\"mtk8\">&#39;rememberme&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">&#39;id_submit&#39;</span><span class=\"mtk1\"> =</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt; </span><span class=\"mtk8\">&#39;wp-submit&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">&#39;remember&#39;</span><span class=\"mtk1\"> =</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt; </span><span class=\"mtk4\">true</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">&#39;value_username&#39;</span><span class=\"mtk1\"> =</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt; </span><span class=\"mtk8\">&#39;&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">&#39;value_remember&#39;</span><span class=\"mtk1\"> =</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt; </span><span class=\"mtk4\">false</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">); ?</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;lt;?php </span><span class=\"mtk11\">wp_login_form</span><span class=\"mtk1\">( </span><span class=\"mtk12\">$args</span><span class=\"mtk1\"> ); ?</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;</span></span></code></pre>\n<p>It will look the same as the one we did earlier but, by customizing the arguments above, you can customize elements of the login form.</p>\n<h2 id=\"handling-the-login-form-response-custom\" style=\"position:relative;\"><a href=\"#handling-the-login-form-response-custom\" aria-label=\"handling the login form response custom 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>Handling the login form response (Custom)</h2>\n<p>To handle the Login Form response we need to grab the $_POST parameters and login the user. You can create this as complex as you like, but I will demonstrate a simpler but effective method.</p>\n<p>For this action, we'll be using the <strong>after<em>setup</em>theme</strong> and <strong>wp_authenticate</strong>. I have added the following two functions within the functions.php file. The first function <strong>optional<em>email</em>address_login</strong> searches for a users email address based on their username, with this functionality you can log in using your email address or the username.</p>\n<p>The second function, <strong>login_user</strong>, handles the actual functionality of the login by receiving the $<em>POST parameters and passing them into the wp</em>signon method.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"php\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk3\">/**</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">* optional_email_address_login allows the user</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">* to log in with a email address as well as a username</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">* </span><span class=\"mtk4\">@param</span><span class=\"mtk3\"> </span><span class=\"mtk4\">string</span><span class=\"mtk3\"> &amp;amp;amp;amp;$username username or email</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">* </span><span class=\"mtk4\">@param</span><span class=\"mtk3\"> </span><span class=\"mtk4\">string</span><span class=\"mtk3\"> &amp;amp;amp;amp;$password password</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">*/</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">function</span><span class=\"mtk1\"> </span><span class=\"mtk11\">optional_email_address_login</span><span class=\"mtk1\">( &amp;amp;amp;amp;</span><span class=\"mtk12\">$username</span><span class=\"mtk1\">, &amp;amp;amp;amp;</span><span class=\"mtk12\">$password</span><span class=\"mtk1\"> ) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">$user</span><span class=\"mtk1\"> = </span><span class=\"mtk11\">get_user_by</span><span class=\"mtk1\">( </span><span class=\"mtk8\">&#39;email&#39;</span><span class=\"mtk1\">, </span><span class=\"mtk12\">$username</span><span class=\"mtk1\"> );</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> ( ! </span><span class=\"mtk11\">empty</span><span class=\"mtk1\">( </span><span class=\"mtk12\">$user</span><span class=\"mtk1\">-</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;user_login ) )</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">$username</span><span class=\"mtk1\"> = </span><span class=\"mtk12\">$user</span><span class=\"mtk1\">-</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;user_login;</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 class=\"mtk3\">// Allows the use of email logins</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk11\">add_action</span><span class=\"mtk1\">( </span><span class=\"mtk8\">&#39;wp_authenticate&#39;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&#39;optional_email_address_login&#39;</span><span class=\"mtk1\">, </span><span class=\"mtk7\">1</span><span class=\"mtk1\">, </span><span class=\"mtk7\">2</span><span class=\"mtk1\"> );</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">/**</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">* login_user handles the $_POST array and logs in users</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">*/</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">function</span><span class=\"mtk1\"> </span><span class=\"mtk11\">login_user</span><span class=\"mtk1\">() {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> ( ! </span><span class=\"mtk11\">is_user_logged_in</span><span class=\"mtk1\">() ) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">$creds</span><span class=\"mtk1\"> = </span><span class=\"mtk11\">array</span><span class=\"mtk1\">();</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">$creds</span><span class=\"mtk1\">[</span><span class=\"mtk8\">&#39;user_login&#39;</span><span class=\"mtk1\">] = </span><span class=\"mtk11\">isset</span><span class=\"mtk1\">( </span><span class=\"mtk12\">$_POST</span><span class=\"mtk1\">[</span><span class=\"mtk8\">&#39;log&#39;</span><span class=\"mtk1\">] ) ? </span><span class=\"mtk12\">$_POST</span><span class=\"mtk1\">[</span><span class=\"mtk8\">&#39;log&#39;</span><span class=\"mtk1\">] : </span><span class=\"mtk8\">&#39;&#39;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">$creds</span><span class=\"mtk1\">[</span><span class=\"mtk8\">&#39;user_password&#39;</span><span class=\"mtk1\">] = </span><span class=\"mtk11\">isset</span><span class=\"mtk1\">( </span><span class=\"mtk12\">$_POST</span><span class=\"mtk1\">[</span><span class=\"mtk8\">&#39;pwd&#39;</span><span class=\"mtk1\">] ) ? </span><span class=\"mtk12\">$_POST</span><span class=\"mtk1\">[</span><span class=\"mtk8\">&#39;pwd&#39;</span><span class=\"mtk1\">] : </span><span class=\"mtk8\">&#39;&#39;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">$creds</span><span class=\"mtk1\">[</span><span class=\"mtk8\">&#39;remember&#39;</span><span class=\"mtk1\">] = </span><span class=\"mtk11\">isset</span><span class=\"mtk1\">( </span><span class=\"mtk12\">$_POST</span><span class=\"mtk1\">[</span><span class=\"mtk8\">&#39;rememberme&#39;</span><span class=\"mtk1\">] ) ? </span><span class=\"mtk4\">true</span><span class=\"mtk1\"> : </span><span class=\"mtk4\">false</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">$user</span><span class=\"mtk1\"> = </span><span class=\"mtk11\">wp_signon</span><span class=\"mtk1\">( </span><span class=\"mtk12\">$creds</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=\"mtk15\">if</span><span class=\"mtk1\"> ( </span><span class=\"mtk11\">is_wp_error</span><span class=\"mtk1\">( </span><span class=\"mtk12\">$user</span><span class=\"mtk1\"> ) ) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk11\">error_log</span><span class=\"mtk1\">( </span><span class=\"mtk12\">$user</span><span class=\"mtk1\">-</span><span class=\"mtk4\">&</span><span class=\"mtk1\">amp;amp;amp;gt;</span><span class=\"mtk11\">get_error_message</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 class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">// Run login_user before headers and cookies are sent</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk11\">add_action</span><span class=\"mtk1\">( </span><span class=\"mtk8\">&#39;after_setup_theme&#39;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&#39;login_user&#39;</span><span class=\"mtk1\"> );</span></span></code></pre>\n<p>In this example I have used the default WordPress login form that you could customize and style to your desire. In the next blog, I will be demonstrating how to build a login form that is fully customized. We won’t be using the provided wordpress functions!</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 .mtk3 { color: #6A9955; }\n  .dark-default-dark .mtk11 { color: #DCDCAA; }\n  .dark-default-dark .mtk8 { color: #CE9178; }\n  .dark-default-dark .mtk12 { color: #9CDCFE; }\n  .dark-default-dark .mtk15 { color: #C586C0; }\n  .dark-default-dark .mtk7 { color: #B5CEA8; }\n</style>","frontmatter":{"date":"March 01, 2016","updated_date":null,"description":null,"title":"Wordpress Custom Login Form Part 1","tags":["WordPress","Learning"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1,"src":"/static/d7e167a0f378c80cdc10b3b3d49b0825/e7487/wordpress-icon-150x1501-150x150.webp","srcSet":"/static/d7e167a0f378c80cdc10b3b3d49b0825/e7487/wordpress-icon-150x1501-150x150.webp 150w","sizes":"(max-width: 150px) 100vw, 150px"}}},"author":{"id":"Zoie Carnegie","github":null,"avatar":null}}}}]},"markdownRemark":{"excerpt":"Introduction Ever wondered how apps like Spotify, Netflix, or Slack manage seamless login experiences across devices? Many of them use JWT…","fields":{"slug":"/engineering/how-to-integrate-jwt/"},"html":"<h2 id=\"introduction\" style=\"position:relative;\"><a href=\"#introduction\" aria-label=\"introduction 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>Introduction</h2>\n<p>Ever wondered how apps like Spotify, Netflix, or Slack manage seamless login experiences across devices? Many of them use JWT, or JSON Web Tokens, a compact, stateless method for securely transmitting user identity and session data across services.</p>\n<p>With JWT token authentication, identity information is embedded in a signed token, allowing you to maintain user sessions without server-side storage. This approach is highly scalable and ideal for modern architectures like SPAs, mobile apps, and microservices.</p>\n<p>In this blog, we’ll walk you through what is JWT, why use it, and how to implement JWT authentication using LoginRadius. </p>\n<p>You’ll learn what JWT is, why it’s effective, and how it works in real-world applications. We'll cover both integration methods (IDX and Direct API), generating your signing key, managing sessions, storing the JWT token securely, and applying best practices throughout.</p>\n<p>Whether you're a developer, product manager, or IAM architect, this guide offers a complete foundation for implementing JWT token authentication into your application stack.</p>\n<h2 id=\"what-is-jwt\" style=\"position:relative;\"><a href=\"#what-is-jwt\" aria-label=\"what is jwt 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 is JWT?</h2>\n<p><a href=\"https://www.loginradius.com/blog/engineering/jwt/\">JSON Web Token (JWT)</a> is an open standard (RFC 7519) used to transmit information securely between parties as a JSON object. It’s compact, self-contained, and digitally signed, making it a reliable format for authentication and authorization across modern applications.</p>\n<p>A JWT consists of three parts:</p>\n<ol>\n<li><strong>Header –</strong> Contains metadata like the type of token and signing algorithm (e.g., HS256).</li>\n<li><strong>Payload –</strong> Stores the actual data or “claims,” such as user ID, roles, and token expiry.</li>\n<li><strong>Signature –</strong> A cryptographic hash that ensures the token hasn’t been tampered with.</li>\n</ol>\n<p><em>Example of a token structure:</em></p>\n<p>&#x3C;base64Header>.&#x3C;base64Payload>.&#x3C;signature></p>\n<h2 id=\"why-use-jwt\" style=\"position:relative;\"><a href=\"#why-use-jwt\" aria-label=\"why use jwt 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 Use JWT?</h2>\n<ul>\n<li><strong>Stateless Authentication</strong>: No server-side session storage is needed — the token holds all necessary user info. </li>\n<li><strong>Portable</strong>: Works seamlessly across domains, services, and APIs. </li>\n<li><strong>Scalable</strong>: Ideal for microservices, SPAs, mobile apps, and serverless functions. </li>\n<li><strong>Interoperable</strong>: JWTs are supported across many languages and frameworks.</li>\n</ul>\n<h2 id=\"how-jwt-works\" style=\"position:relative;\"><a href=\"#how-jwt-works\" aria-label=\"how jwt works 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 JWT Works?</h2>\n<p><img src=\"/f29edbf2978577390c7ffa02e9bc4dda/lr-JWT-authentication.webp\" alt=\"Flowchart illustrating LoginRadius JWT authentication via Identity Provider (IDP), showing user redirection from login icon to login page, authentication with IDP, JWT token validation, and subsequent redirection to the customer&#x27;s website or error page based on validation results.\"></p>\n<ol>\n<li>A user logs in with credentials. </li>\n<li>Your app (or identity provider like LoginRadius) issues a signed JWT. </li>\n<li>The client stores the token and sends it with each request (usually in the Authorization header). </li>\n<li>The server validates the token’s signature and claims. </li>\n<li>If valid, access is granted — without any session stored on the backend.</li>\n</ol>\n<p>JWT simplifies identity verification, especially when you're building apps that talk to APIs or need to scale without centralized session storage.</p>\n<h2 id=\"jwt-authentication-with-loginradius-overview\" style=\"position:relative;\"><a href=\"#jwt-authentication-with-loginradius-overview\" aria-label=\"jwt authentication with loginradius overview 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>JWT Authentication with LoginRadius: Overview</h2>\n<p>LoginRadius provides robust support for JWT (JSON Web Token) authentication, which allows for flexible and secure access control across different digital platforms. Whether you're building a fully custom identity flow or using a pre-built interface, the platform supports various integration approaches depending on your architecture.</p>\n<p>If you're looking to understand how to implement JWT token authentication effectively, LoginRadius offers two primary implementation models that cater to different levels of customization and control:</p>\n<h3 id=\"1-idx-implementation--jwt-through-a-hosted-login-page\" style=\"position:relative;\"><a href=\"#1-idx-implementation--jwt-through-a-hosted-login-page\" aria-label=\"1 idx implementation  jwt through a hosted login page 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. IDX Implementation – JWT through a Hosted Login Page</h3>\n<p>The IDX-hosted login approach enables secure, standards-compliant, JWT-based authentication without requiring you to build a custom login interface. This is a strategic option for fast, compliant, and user-friendly deployments.</p>\n<ul>\n<li>The Identity Experience Framework (IDX) comes with a fully custom branded hosted login page.</li>\n<li>Once the user logs in and gets enrolled, the user’s JWTs are automatically generated and issued. These tokens can be utilized for managing user sessions and accessing the APIs.</li>\n<li>This approach simplifies deployment without compromising on user experience and security standards.</li>\n</ul>\n<h3 id=\"configuration-steps\" style=\"position:relative;\"><a href=\"#configuration-steps\" aria-label=\"configuration steps 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><strong>Configuration Steps:</strong></h3>\n<ol>\n<li>Enable JWT Login</li>\n<li>Go to <a href=\"https://console.loginradius.com/authentication/authentication-configuration\">authentication configuration settings</a> and enable JWT Login in the Admin Console.</li>\n</ol>\n<p><img src=\"/9fb19dd9c88c7916aeebd03ab6e661b7/lr-admin-console.webp\" alt=\"Screenshot of LoginRadius Admin Console showing JWT Custom IDP configuration interface with options for provider name, algorithm (HS256), key entry, clock skew, and expiration time settings.\"></p>\n<ol start=\"2\">\n<li>Specify your signing algorithm and expiry policy, and define your JWT Secret Key.</li>\n<li>Input a secure JWT signing key.</li>\n<li>Specify token expiry duration (e.g., 15–60 minutes)</li>\n<li>Select the desired algorithm —HS256 for symmetric signing (same key signs and verifies)</li>\n<li>RS256 for asymmetric signing, where LoginRadius securely stores the private key used to sign the JWT.</li>\n<li>Your app or backend service uses the public key to validate the token signature.</li>\n<li>LoginRadius provides a JWKS (JSON Web Key Set) endpoint to dynamically fetch and rotate public keys, ensuring trust without key exposure.</li>\n<li>Update IDX Template for Callback</li>\n<li>Modify your IDX login page template to retrieve the JWT post-login. You can access the token via redirect URL parameters or secure JavaScript callbacks.</li>\n</ol>\n<h3 id=\"example-response\" style=\"position:relative;\"><a href=\"#example-response\" aria-label=\"example 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>Example Response:</h3>\n<p>{</p>\n<p>  \"access_token\": \"eyJhbGciOiJIUzI1NiIsInR...\",</p>\n<p>  \"expires_in\": 1800</p>\n<p>}</p>\n<p>This integration approach works best for all teams that want effective identity workflows without the complexity of building proprietary login screens, something that is crucial for customer portals, onboarding of mobile applications, and even managing access for business partners.</p>\n<h3 id=\"2-direct-api-implementation--self-managed-login\" style=\"position:relative;\"><a href=\"#2-direct-api-implementation--self-managed-login\" aria-label=\"2 direct api implementation  self managed login 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. Direct API Implementation – Self Managed Login</h3>\n<p>If you’re building a custom login UI or working in a headless environment, LoginRadius lets you generate and handle JWTs directly through its <a href=\"https://www.loginradius.com/docs/api/v2/customer-identity-api/\">Authentication APIs</a>. Here’s how you can programmatically perform token authentication using the classic method:</p>\n<ul>\n<li>For custom front-end applications, LR offers an API to authenticate users and issue JWT tokens.</li>\n<li>In response to the login request, the developers are provided with signed tokens that can be validated on the client’s side or by downstream services.</li>\n<li>This method is best fit for enterprise applications that have complex custom workflows or are designed to be embedded into other applications.</li>\n</ul>\n<h3 id=\"configuration-steps-1\" style=\"position:relative;\"><a href=\"#configuration-steps-1\" aria-label=\"configuration steps 1 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><strong>Configuration Steps:</strong></h3>\n<h4 id=\"step-1-authenticate-via-api\" style=\"position:relative;\"><a href=\"#step-1-authenticate-via-api\" aria-label=\"step 1 authenticate via api 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>Step 1: Authenticate via API:</h4>\n<ul>\n<li>\n<p>Send a POST login request to the LR Authentication URL: </p>\n<p>POST /identity/v2/auth/login</p>\n</li>\n</ul>\n<p>Include the user’s credentials (email + password) in the request body.</p>\n<h4 id=\"step-2-get-jwt-in-response\" style=\"position:relative;\"><a href=\"#step-2-get-jwt-in-response\" aria-label=\"step 2 get jwt in 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>Step 2: Get JWT in Response</h4>\n<ul>\n<li>If the user credentials are authentic, then the JWT token will be available in response.</li>\n</ul>\n<p>{</p>\n<p> \"access_token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...\",</p>\n<p> \"expires_in\": 3600</p>\n<p>}</p>\n<h4 id=\"step-3-jwt-decoding-and-validation\" style=\"position:relative;\"><a href=\"#step-3-jwt-decoding-and-validation\" aria-label=\"step 3 jwt decoding and validation 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>Step 3: JWT Decoding and Validation</h4>\n<ul>\n<li>Use any JWT library (e.g., jsonwebtoken for Node.js or pyjwt for Python) to decode the token.</li>\n<li>Validate the signature using your configured secret key.</li>\n<li>Confirm claims like exp, iat, aud, and iss.</li>\n</ul>\n<h4 id=\"step-4-set-custom-claims-optional\" style=\"position:relative;\"><a href=\"#step-4-set-custom-claims-optional\" aria-label=\"step 4 set custom claims optional 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>Step 4: Set Custom Claims (Optional)</h4>\n<p>With LoginRadius, it is possible to customize the payload to include user roles and/or any additional metadata. You can set custom JWT claims on the Admin Console.</p>\n<p>With this method, you have complete customization over login flows while using LoginRadius to issue signed JWTs for user session management.</p>\n<p><strong>NOTE-</strong> With either method, LoginRadius ensures that JWTs are securely signed, optionally short-lived, and compatible with standard token validation libraries, making integration seamless for everyone.</p>\n<p>To get started with JWT implementation, you can<a href=\"https://www.loginradius.com/docs/single-sign-on/federated-sso/jwt-login/jwt-implementation-guide/\"> read our complete developer documentation</a>. </p>\n<h2 id=\"hosted-login-vs-direct-api\" style=\"position:relative;\"><a href=\"#hosted-login-vs-direct-api\" aria-label=\"hosted login vs direct api 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>Hosted Login vs Direct API</h2>\n<p><img src=\"/15ec02ac98d24a9f1f28e5d0f06b9174/IDX-vs-Direct-API-JWT.webp\" alt=\"Illustration showing IDX vs Direct API JWT flow diagram comparing LoginRadius JWT authentication methods via Hosted Login Page (IDX) and Custom Login UI using Direct API, illustrating user login, JWT issuance, and token return process.\"></p>\n<h2 id=\"what-is-session-management-and-how-it-works-with-jwt\" style=\"position:relative;\"><a href=\"#what-is-session-management-and-how-it-works-with-jwt\" aria-label=\"what is session management and how it works with jwt 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 is Session Management and How It Works with JWT</h2>\n<p><a href=\"https://www.loginradius.com/blog/identity/user-session-management/\">Session management </a>is how your app keeps track of a user after they log in so they don’t have to prove who they are with every request.</p>\n<p>In traditional apps, sessions are stored on the server using session IDs. Every time a request comes in, the server checks that session ID to verify the user.</p>\n<p>In modern apps, especially SPAs and APIs, JWTs are used to manage sessions without needing server-side storage; this is called stateless session management. The token itself carries the user’s identity, roles, and expiration details. As long as the token is valid, the user stays logged in.</p>\n<p>Good session management ensures:</p>\n<ul>\n<li>Security against session hijacking</li>\n<li>Fast user validation without hitting a database</li>\n<li>Smooth experiences with token refresh strategies</li>\n</ul>\n<h2 id=\"how-loginradius-handles-session-management-with-jwt\" style=\"position:relative;\"><a href=\"#how-loginradius-handles-session-management-with-jwt\" aria-label=\"how loginradius handles session management with jwt 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 LoginRadius Handles Session Management with JWT:</h2>\n<ol>\n<li>\n<p>User Logs In </p>\n<ul>\n<li>LoginRadius returns an access token (JWT) and, optionally, a refresh token.</li>\n</ul>\n</li>\n<li>\n<p>Client Stores the Token </p>\n<ul>\n<li>Access tokens are stored in memory, sessionStorage, or secure cookies. </li>\n<li>They’re sent on every request via the Authorization: Bearer header. </li>\n</ul>\n</li>\n<li>\n<p>Access Token Expiry </p>\n<ul>\n<li>These tokens are short-lived by design (e.g., 15–30 minutes). </li>\n<li>Once expired, the client can use the refresh token to request a new access token. </li>\n</ul>\n</li>\n<li>\n<p>Token Renewal </p>\n<ul>\n<li>LoginRadius validates the refresh token and issues a new JWT, i.e., no user re-authentication is needed. </li>\n<li>Refresh tokens can be revoked at any time.</li>\n</ul>\n</li>\n<li>Logout and Token Revocation Strategy</li>\n</ol>\n<p>When the user logs out, both the access token and refresh token should be cleared from client storage.</p>\n<ul>\n<li>The refresh token can be explicitly revoked via the LoginRadius API, terminating the ability to renew sessions. </li>\n<li>\n<p>However, access tokens are stateless and cannot be revoked mid-lifecycle unless: </p>\n<ul>\n<li>You maintain a blacklist of token IDs (jti claims) and check them on each request. </li>\n<li>You use short-lived access tokens to limit exposure naturally. </li>\n<li>Or, you rotate your JWT signing key, invalidating all previously issued tokens. </li>\n</ul>\n</li>\n</ul>\n<p>Combining these strategies gives you greater control over token misuse and enables a robust, enterprise-grade logout flow. </p>\n<p><a href=\"https://www.loginradius.com/resource/whitepaper/secure-api-using-oauth2\"><img src=\"/e55ae4bbc8ce62e13f03e46e29ebe7cc/api-economy.webp\" alt=\"illustration showing LoginRadius free downloadable resource named API economy is transforming digitization: how to secure it using oauth 2.0.\"></a></p>\n<h2 id=\"how-to-store-jwt-tokens\" style=\"position:relative;\"><a href=\"#how-to-store-jwt-tokens\" aria-label=\"how to store jwt tokens 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 Store JWT Tokens?</h2>\n<p>When you implement JWT-based authentication, the client (browser or mobile app) needs a way to store the access token and, optionally, the refresh token after they are issued by the authentication server. This stored token is then attached to every subsequent request to prove the user's identity.</p>\n<p>Choosing where to store the JWT is a crucial security decision. The most common storage options are:</p>\n<ul>\n<li>localStorage</li>\n<li>sessionStorage</li>\n<li>HTTP-only cookies</li>\n</ul>\n<p>Each option has trade-offs between security, accessibility, and persistence, and the right choice depends on your application's architecture and threat model.</p>\n<h4 id=\"recommended-storage-strategy\" style=\"position:relative;\"><a href=\"#recommended-storage-strategy\" aria-label=\"recommended storage strategy 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>Recommended Storage Strategy</h4>\n<ul>\n<li>\n<p>Access Tokens </p>\n<ul>\n<li>For SPAs: store in memory or sessionStorage for short-term access </li>\n<li>If stored in the browser, protect against XSS </li>\n</ul>\n</li>\n<li>\n<p>Refresh Tokens</p>\n<ul>\n<li>Always store the JWT refresh token in HTTP-only secure cookies to prevent JavaScript access. This adds a critical layer of protection against XSS attacks.</li>\n<li>Combine with SameSite=Strict or SameSite=Lax attributes to mitigate CSRF risks and ensure the JWT refresh token is only sent in intended contexts.</li>\n</ul>\n</li>\n</ul>\n<h2 id=\"best-practices-for-storing-jwts\" style=\"position:relative;\"><a href=\"#best-practices-for-storing-jwts\" aria-label=\"best practices for storing jwts 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>Best Practices for Storing JWTs</h2>\n<ol>\n<li>Never store sensitive tokens (like refresh tokens) in localStorage or sessionStorage.</li>\n<li>Use Secure and HttpOnly flags with cookies to prevent JavaScript access and ensure transmission only over HTTPS.</li>\n<li>Set the SameSite=Strict or Lax attribute on cookies to protect against CSRF.</li>\n<li>Use short-lived access tokens and rotate refresh tokens regularly.</li>\n<li>Implement CSP (Content Security Policy) to reduce XSS risk.</li>\n<li>Avoid storing any tokens in frontend code (e.g., hardcoded in JS files).</li>\n</ol>\n<h2 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</h2>\n<p>JWT authentication with LoginRadius offers a modern, stateless approach to managing sessions across distributed systems. The IDX integration is ideal for rapid deployment, while the Direct API model is best for organizations needing deep customization and integration flexibility.</p>\n<p>With robust token signing, refresh capabilities, and centralized control, LoginRadius provides a future-ready foundation for secure, scalable identity architecture. <a href=\"https://www.loginradius.com/contact-us?utm_source=blog&#x26;utm_medium=web&#x26;utm_campaign=how-to-integrate-jwt\">Contact us</a> to know more about JWT authentication and implementation guide. </p>\n<h2 id=\"faqs\" style=\"position:relative;\"><a href=\"#faqs\" aria-label=\"faqs 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>FAQs</h2>\n<h3 id=\"1-what-is-jwt-authentication-used-for\" style=\"position:relative;\"><a href=\"#1-what-is-jwt-authentication-used-for\" aria-label=\"1 what is jwt authentication used for 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. What is JWT authentication used for?</h3>\n<p><strong>A:</strong> JWT authentication securely verifies user identities, enabling stateless session management across web, mobile apps, and microservices without server-side session storage.</p>\n<h3 id=\"2-how-does-loginradius-simplify-jwt-integration\" style=\"position:relative;\"><a href=\"#2-how-does-loginradius-simplify-jwt-integration\" aria-label=\"2 how does loginradius simplify jwt integration 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. How does LoginRadius simplify JWT integration?</h3>\n<p><strong>A:</strong> LoginRadius simplifies JWT integration by offering hosted <a href=\"https://www.loginradius.com/docs/single-sign-on/federated-sso/jwt-login/jwt-implementation-guide/\">IDX login pages </a>and direct API-based authentication methods, enabling rapid deployment and deep customization.</p>\n<h3 id=\"3-is-jwt-authentication-secure\" style=\"position:relative;\"><a href=\"#3-is-jwt-authentication-secure\" aria-label=\"3 is jwt authentication secure 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. Is JWT authentication secure?</h3>\n<p><strong>A:</strong> Yes, JWT authentication is secure when implemented with best practices like short-lived tokens, secure storage methods, signature validation, and refresh token rotation.</p>\n<h3 id=\"4-can-jwt-tokens-be-revoked-with-loginradius\" style=\"position:relative;\"><a href=\"#4-can-jwt-tokens-be-revoked-with-loginradius\" aria-label=\"4 can jwt tokens be revoked with loginradius 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>4. Can JWT tokens be revoked with LoginRadius?</h3>\n<p><strong>A:</strong> Yes, LoginRadius allows<a href=\"https://www.loginradius.com/docs/api/v2/customer-identity-api/refresh-token/revoke-refresh-token/?q=revoke+jwt\"> revocation of JWT</a> refresh tokens explicitly, and supports strategies like short-lived tokens and key rotation to manage token lifecycles securely.</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":"April 15, 2025","updated_date":null,"description":"Discover JWT (JSON Web Token) authentication, its advantages, and how to integrate it seamlessly using LoginRadius' hosted IDX and Direct API methods for secure, scalable identity management.","title":"JWT Authentication with LoginRadius: Quick Integration Guide","tags":["JWT","JSON Web Token","Authentication","Authorization"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":0.7782101167315175,"src":"/static/4cedb7829f98208cbc6d5a9aea4e983d/58556/how-to-integrate-jwt.webp","srcSet":"/static/4cedb7829f98208cbc6d5a9aea4e983d/61e93/how-to-integrate-jwt.webp 200w,\n/static/4cedb7829f98208cbc6d5a9aea4e983d/1f5c5/how-to-integrate-jwt.webp 400w,\n/static/4cedb7829f98208cbc6d5a9aea4e983d/58556/how-to-integrate-jwt.webp 800w,\n/static/4cedb7829f98208cbc6d5a9aea4e983d/1cc9f/how-to-integrate-jwt.webp 896w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Kundan Singh","github":null,"avatar":null}}}},"pageContext":{"limit":6,"skip":252,"currentPage":43,"type":"//engineering//","numPages":53,"pinned":"5c425581-f474-5ae9-abe7-cf5342db2aaa"}},"staticQueryHashes":["1171199041","1384082988","2100481360","23180105","528864852"]}