<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ashik</title>
    <description>The latest articles on Forem by Ashik (@ashikrnhq04).</description>
    <link>https://forem.com/ashikrnhq04</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F814208%2F5adb7a2f-28b2-4614-8d76-57e853447f62.png</url>
      <title>Forem: Ashik</title>
      <link>https://forem.com/ashikrnhq04</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ashikrnhq04"/>
    <language>en</language>
    <item>
      <title>I Built FocusedMind - A Chrome Extension That Helps You Focus</title>
      <dc:creator>Ashik</dc:creator>
      <pubDate>Fri, 11 Jul 2025 17:34:47 +0000</pubDate>
      <link>https://forem.com/ashikrnhq04/i-built-focusedmind-a-chrome-extension-that-helps-you-focus-1mfi</link>
      <guid>https://forem.com/ashikrnhq04/i-built-focusedmind-a-chrome-extension-that-helps-you-focus-1mfi</guid>
      <description>&lt;p&gt;Let's be honest - how many times have you started working on something important, only to find yourself scrolling through social media 10 minutes later? Or opened a new tab to "quickly check" something and ended up in a 2-hour YouTube rabbit hole?&lt;/p&gt;

&lt;p&gt;I've been there. We've all been there.&lt;/p&gt;

&lt;p&gt;Most website blockers say "NO" and leave you staring at a blank screen, feeling frustrated. But what if there was a better way?&lt;/p&gt;

&lt;h2&gt;
  
  
  Introducing FocusedMind 🚀
&lt;/h2&gt;

&lt;p&gt;FocusedMind isn't just another website blocker - it's your focus coach that helps you build better concentration habits through positive reinforcement and real-time feedback.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Features That Matter
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Category blocking:&lt;/strong&gt; You can block sites based on category, like Social Media, News, Entertainment and Adult Content. Based on category selection, the extension will show you a warning on the blocked sites. &lt;/p&gt;

&lt;p&gt;Custom URLs: The list of sites is pre-defined to keep the extension simple and skip the API call. So, in case of a custom URL, you've the option to block in the custom URL option.&lt;/p&gt;

&lt;p&gt;Whitelist mode: Only allow essential sites during focus time&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real-Time Feedback&lt;/li&gt;
&lt;li&gt;Real-Time Live distraction counter&lt;/li&gt;
&lt;li&gt;Dynamic efficiency rating&lt;/li&gt;
&lt;li&gt;Motivational messaging based on your performance&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why I Built This 🛠️
&lt;/h2&gt;

&lt;p&gt;As a developer, I know a bunch of productivity software with a lot of features, and they all felt punitive. They'd block a site and make me feel bad about it. Also, I felt lost in the features. So I wanted something that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Encourages growth instead of punishment&lt;/li&gt;
&lt;li&gt;Provides insights into my focus patterns&lt;/li&gt;
&lt;li&gt;Celebrates progress rather than highlighting failures&lt;/li&gt;
&lt;li&gt;Adapts to my needs instead of being rigid&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Under the Hood ⚙️
&lt;/h2&gt;

&lt;p&gt;Built with modern Chrome Extension Manifest V3:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Background Service Worker for persistent session management&lt;/li&gt;
&lt;li&gt;Content Scripts for real-time website blocking&lt;/li&gt;
&lt;li&gt;Smart URL parsing handles various formats automatically&lt;/li&gt;
&lt;li&gt;Chrome Storage API for seamless data persistence&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Ready to Try?
&lt;/h2&gt;

&lt;p&gt;-- &lt;a href="https://chromewebstore.google.com/detail/focusedmind/ignbmkkcgdkabggpcmdfhkgliajbnaid" rel="noopener noreferrer"&gt;Install FocusedMind on Chrome&lt;/a&gt;, use it, and &lt;em&gt;leave your feedback.&lt;/em&gt; &lt;br&gt;
-- Share with your team and help others find focus to&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Heads-up: Chrome may show a warning during installation since FocusedMind is still new on the store. Rest assured — this extension runs locally, makes no API calls, and does not collect any user data. Your privacy and focus are fully respected.&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;I'll be sharing my journey of building this extension soon. So if you're a dev with an idea and decent JavaScript chops, you'll see how visualization turns into execution.&lt;/p&gt;

&lt;p&gt;Comment below with your feedback, suggestions, and features you think will add value.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>extensions</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>DOM</title>
      <dc:creator>Ashik</dc:creator>
      <pubDate>Fri, 20 Jun 2025 16:53:35 +0000</pubDate>
      <link>https://forem.com/ashikrnhq04/dom-42cl</link>
      <guid>https://forem.com/ashikrnhq04/dom-42cl</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/ashikrnhq04/javascript-dom-manipulation-2998" class="crayons-story__hidden-navigation-link"&gt;JavaScript DOM Manipulation&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/ashikrnhq04" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F814208%2F5adb7a2f-28b2-4614-8d76-57e853447f62.png" alt="ashikrnhq04 profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/ashikrnhq04" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Ashik
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Ashik
                
              
              &lt;div id="story-author-preview-content-2402865" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/ashikrnhq04" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F814208%2F5adb7a2f-28b2-4614-8d76-57e853447f62.png" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Ashik&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/ashikrnhq04/javascript-dom-manipulation-2998" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Apr 12 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/ashikrnhq04/javascript-dom-manipulation-2998" id="article-link-2402865"&gt;
          JavaScript DOM Manipulation
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/javascript"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;javascript&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/programming"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;programming&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/tutorial"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;tutorial&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
            &lt;a href="https://dev.to/ashikrnhq04/javascript-dom-manipulation-2998#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              &lt;span class="hidden s:inline"&gt;Add Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            4 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>Ashik</dc:creator>
      <pubDate>Mon, 16 Jun 2025 18:45:38 +0000</pubDate>
      <link>https://forem.com/ashikrnhq04/-280n</link>
      <guid>https://forem.com/ashikrnhq04/-280n</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/ashikrnhq04/zod-an-ultimate-validation-library-4048" class="crayons-story__hidden-navigation-link"&gt;Zod: The Ultimate Validation Library for TypeScript&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/ashikrnhq04" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F814208%2F5adb7a2f-28b2-4614-8d76-57e853447f62.png" alt="ashikrnhq04 profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/ashikrnhq04" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Ashik
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Ashik
                
              
              &lt;div id="story-author-preview-content-2545694" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/ashikrnhq04" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F814208%2F5adb7a2f-28b2-4614-8d76-57e853447f62.png" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Ashik&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/ashikrnhq04/zod-an-ultimate-validation-library-4048" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;May 30 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/ashikrnhq04/zod-an-ultimate-validation-library-4048" id="article-link-2545694"&gt;
          Zod: The Ultimate Validation Library for TypeScript
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/tutorial"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;tutorial&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/zod"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;zod&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/typescript"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;typescript&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/ashikrnhq04/zod-an-ultimate-validation-library-4048" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;2&lt;span class="hidden s:inline"&gt; reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/ashikrnhq04/zod-an-ultimate-validation-library-4048#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              &lt;span class="hidden s:inline"&gt;Add Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            5 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>tutorial</category>
      <category>zod</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Zod: The Ultimate Validation Library for TypeScript</title>
      <dc:creator>Ashik</dc:creator>
      <pubDate>Fri, 30 May 2025 16:20:19 +0000</pubDate>
      <link>https://forem.com/ashikrnhq04/-59i3</link>
      <guid>https://forem.com/ashikrnhq04/-59i3</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/ashikrnhq04/zod-an-ultimate-validation-library-4048" class="crayons-story__hidden-navigation-link"&gt;Zod: The Ultimate Validation Library for TypeScript&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/ashikrnhq04" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F814208%2F5adb7a2f-28b2-4614-8d76-57e853447f62.png" alt="ashikrnhq04 profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/ashikrnhq04" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Ashik
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Ashik
                
              
              &lt;div id="story-author-preview-content-2545694" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/ashikrnhq04" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F814208%2F5adb7a2f-28b2-4614-8d76-57e853447f62.png" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Ashik&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/ashikrnhq04/zod-an-ultimate-validation-library-4048" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;May 30 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/ashikrnhq04/zod-an-ultimate-validation-library-4048" id="article-link-2545694"&gt;
          Zod: The Ultimate Validation Library for TypeScript
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/tutorial"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;tutorial&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/zod"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;zod&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/typescript"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;typescript&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/ashikrnhq04/zod-an-ultimate-validation-library-4048" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;2&lt;span class="hidden s:inline"&gt; reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/ashikrnhq04/zod-an-ultimate-validation-library-4048#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              &lt;span class="hidden s:inline"&gt;Add Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            5 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>tutorial</category>
      <category>zod</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Zod: The Ultimate Validation Library for TypeScript</title>
      <dc:creator>Ashik</dc:creator>
      <pubDate>Fri, 30 May 2025 15:15:57 +0000</pubDate>
      <link>https://forem.com/ashikrnhq04/zod-an-ultimate-validation-library-4048</link>
      <guid>https://forem.com/ashikrnhq04/zod-an-ultimate-validation-library-4048</guid>
      <description>&lt;p&gt;This post was originally posted here on my site &lt;a href="https://codespoetry.com" rel="noopener noreferrer"&gt;codespoetry.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Zod is a TypeScript-first schema validation library. Unlike static type checking, Zod helps you to validate data dynamically at runtime. Whether user input, API response, or any data you want to validate, structure custom errors, Zod is the ultimate tool.&lt;/p&gt;

&lt;p&gt;I’ll go through the discussion on schema structure, custom validation, asynchronous checks, and demonstrate how to integrate Zod into a React/Next.js project for form validation, state management, and prop type validation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Zod Use Cases
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Schema Definitions
&lt;/h3&gt;

&lt;p&gt;Defining a complex schema using Zod is fun. Array, Object, nested data, nothing is as complex as we may think. Imagine a address schema:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {z} from 'zod';

const addressSchema = z.object({
  area: z.string(),
  city: z.string(),
  zipCode: z.string().regex(/^\d{5}$/, "Invalid zip code"),  
  country: z.string(),
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This schema will validate the address and ensure type safety. We can also set custom errors on validation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {z} from 'zod';

const addressSchema = z.object({
  area: z.string({ required_error: "Area is required" }),
  city: z.string({ required_error: "City is required" }),
  zipCode: z.string({ required_error: "Zip code is required" }).regex(/^\d{5}$/, "Invalid     zip code"),  
  country: z.string({ required_error: "Country is required" }),
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This schema will validate the data types and return an error if any field is missing or empty. We can also chain the validation methods. And here are a few examples&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// validate both undefined and empty fields or data 
z.string().nonempty()

// validate undefined, nonempty, minimum characters
z.string().nonempty().min(100);

// validate undefined, nonempty, minimum and max characters
z.string().nonempty().min(100).max(500);

// setting up custom error message
z.string({ required_error: "String is required" })
.nonempty({message: "String can't be empty"})
.min(100, {message: "A minimum of 100 characters is required"})
.max(500, {message: "String can't be more than 500 characters"}); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that in the validation chain, if multiple validations fail, the last error message will be assigned to the error data. For example, for a blank text field, both ‘nonempty’ and ‘min’ are correct. And the error defined in the min() method will be added to the error data. This is how Zod prioritizes errors when multiple rules fail.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Advance validations
&lt;/h3&gt;

&lt;p&gt;All the default validation methods can be used in different contexts. Like, you can use the ‘min()’ method in array data to ensure a minimum of data is present. Get back to the address schema&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {z} from 'zod';

const addressSchema = z.array(
z.object({
  area: z.string({ required_error: "Area is required" }),
  city: z.string({ required_error: "City is required" }),
zipCode: z.string({ required_error: "Zip code is required" }).regex(/^\d{5}$/, "Invalid zip code"),  
country: z.string({ required_error: "Country is required" }),
})
).min(1, {message: "A minimum of one address is required"});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will prevent form submission if there is no address in the submitted data. The address object will be in an array, as this is wrapped in Zod array data, to clarify. We can also use other methods to validate our data or a collection of data.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Custom Validations
&lt;/h3&gt;

&lt;p&gt;In addition to the default validation methods, our project may require custom validations. Calculating age based on DOB input, comparing dates, validating a field’s data that depends on a different field, etc. Zod has refine and superrefine methods to implement custom validation. The refine is a syntactic sugar of superrefine. Here is how we can use refine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;jobDescription: z.string().refine((value) =&amp;gt; {
         if (value.trim().split(" ").length &amp;gt; 500) {
           return false;
         }
         return true;
         },
         { message: "Job description can't be more than 500 words" }
       ).optional(),

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above Zod schema checks if the job description words are longer than 500 words. If it is, it will return false. However, it's an optional data as we added Zod's optional() method. &lt;/p&gt;

&lt;p&gt;The refine method should always return a boolean. If it’s untrue, the validation fails, and the error state updates with the message passed as the second argument to the refine function. To clarify the entire scenario, the refine method takes two arguments. The first one is a validation function. You can check the value and run your refinement as you want to validate your data. The second argument should be an Object containing a message for the error state. The default Zod’s max() method checks characters. Our goal was to validate words. So, we used refine here.&lt;/p&gt;

&lt;p&gt;As I discussed in “Advance Validations” how we can chain validation methods, we can chain the refine() method as well and validate our data with different conditions. We can also run the refine() method on a whole object data group or on the array. For a data group, we’ll get all the data in the value parameter. Here is an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;z
  .array(
    z
      .object({
        company: z
          .string({ required_error: "Comapny name is required" })
          .nonempty({ message: "Company name can't be empty" }),
        jobTitle: z
          .string({ required_error: "Job title is required" })
          .nonempty({
            message: "Job title can't be empty",
          }),
        startingDate: z.date({ required_error: "Starting date is required" }),
        endDate: z
          .date({ required_error: "End date is required" })
          .optional()
          .nullable(),
        currentlyWorking: z.boolean().optional(),
        jobDescription: z
          .string()
          .refine(
            (value) =&amp;gt; {
              if (value.trim().split(" ").length &amp;gt; 500) {
                return false;
              }
              return true;
            },
            { message: "Job description can't be more than 500 words" }
          )
          .optional(),
      })
      .refine(
        (date) =&amp;gt; {
          if (date.currentlyWorking) return true;
          return compareDesc(date.startingDate, date.endDate ?? new Date()) ==
            0 ||
            compareDesc(date.startingDate, date.endDate ?? new Date()) == -1
            ? false
            : true;
        },
        {
          message:
            "Star and End date can't be the same or End date is before the Start date",
          path: ["endDate"],
        }
      )
  )
  .optional()
  .default([]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The compareDesc function is from date-fns to check date equality.&lt;/p&gt;

&lt;p&gt;We can also pass an async function as our validator and validate data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const stringSchema = z.string().refine(async (val) =&amp;gt; val.length &amp;lt;= 8);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Zod’s parse and parseAsync are the methods to parse a Zod schema and check if the data is valid. The parseAsync method is used to validate data asynchronously for an asynchronous validation function passed to the refine method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const stringSchema = z.string();

stringSchema.parse("fish"); // =&amp;gt; returns "fish"
stringSchema.parse(12); // throws error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The parse and parseAsync throw an error on failing validation. If we want to get an object containing parsed data or an error, we can use safeParse and safeParseAsync.&lt;/p&gt;

&lt;h2&gt;
  
  
  Integration Zod into a React Project
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Form validation with React Hook Form
&lt;/h3&gt;

&lt;p&gt;Zod pairs beautifully with form libraries like React Hook Form for validating user inputs. Here’s a login form example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';

const schema = z.object({
  email: z.string().email(),
  password: z.string().min(8),
});

function LoginForm() {
  const { register, handleSubmit, formState: { errors } } = useForm({
    resolver: zodResolver(schema),
  });

  const onSubmit = (data) =&amp;gt; {
    console.log("Valid data:", data);
  };

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;input {...register("email")} placeholder="Email" /&amp;gt;
      {errors.email &amp;amp;&amp;amp; &amp;lt;p&amp;gt;{errors.email.message}&amp;lt;/p&amp;gt;}
      &amp;lt;input type="password" {...register("password")} placeholder="Password" /&amp;gt;
      {errors.password &amp;amp;&amp;amp; &amp;lt;p&amp;gt;{errors.password.message}&amp;lt;/p&amp;gt;}
      &amp;lt;button onClick={handleSubmit(onSubmit)}&amp;gt;Login&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Zod validates the form data, and React Hook Form manages the UI state, displaying errors as needed.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Prop Types Validation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const propsSchema = z.object({
  title: z.string(),
  count: z.number().int().positive(),
});

function MyComponent(props) {
  const validatedProps = propsSchema.parse(props);
  return &amp;lt;div&amp;gt;{validatedProps.title}: {validatedProps.count}&amp;lt;/div&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Zod provides detailed errors if props don’t match the schema, enhancing debugging.&lt;/p&gt;

&lt;h2&gt;
  
  
  Zod Documentations:
&lt;/h2&gt;

&lt;p&gt;Zod has its rich documentation on use cases. You can check it out here and dive deep.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Zod is a handy, small yet powerful tool to enhance your development skills. Zod provides clear error messages and a straightforward API. This makes it an excellent choice for TypeScript applications needing robust data validation.&lt;/p&gt;

&lt;p&gt;If you like this article, feel free to share it in your network and comment below with any feedback or suggestions.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>zod</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Power of WP-CLI: Streamline Your WordPress Workflow</title>
      <dc:creator>Ashik</dc:creator>
      <pubDate>Mon, 05 May 2025 12:00:56 +0000</pubDate>
      <link>https://forem.com/ashikrnhq04/power-of-wp-cli-streamline-your-wordpress-workflow-4k46</link>
      <guid>https://forem.com/ashikrnhq04/power-of-wp-cli-streamline-your-wordpress-workflow-4k46</guid>
      <description>&lt;p&gt;Here is the original post &lt;a href="https://codespoetry.com/power-of-wp-cli-streamline-your-wordpress-workflow/" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;WP-CLI is a powerful command-line interface for managing WordPress installations. Whether you're a site owner, developer, or working on a client project, WP-CLI can significantly speed up your workflow.&lt;/p&gt;

&lt;p&gt;If you're familiar with command-line tools, such as Linux terminal, Windows PowerShell, or the macos command line, you're well-prepared to start using WP-CLI. If not yet, that's also ok with some practices to be familiar with. With just a few commands, you can streamline updates, manage plugins and themes, create users, and much more.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Getting Started with WP-CLI&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Installation:&lt;/strong&gt; Follow the simple steps on &lt;a href="https://wp-cli.org/" rel="noopener noreferrer"&gt;https://wp-cli.org/&lt;/a&gt; to install it on your operating system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic Usage:&lt;/strong&gt; Open your terminal, navigate to your WordPress directory or login to your hosting through SSH, and type &lt;code&gt;wp&lt;/code&gt; followed by your command.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why Use It?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;WP-CLI allows you to perform a wide range of tasks using the command line without logging in to the WordPress dashboard. This helps you automate repetitive tasks, easily manage multiple sites, or run various operations that would be otherwise time-consuming through the graphical interface.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Use Cases for WP-CLI&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Here are some practical scenarios where WP-CLI shines, complete with example commands to demonstrate its power:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Updating WordPress Core, Plugins, and Themes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;With WP-CLI, you can update everything in seconds.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Update WordPress core:&lt;/strong&gt; &lt;code&gt;wp core update&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Update all plugins:&lt;/strong&gt; &lt;code&gt;wp plugin update --all&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Update all themes:&lt;/strong&gt; &lt;code&gt;wp theme update --all&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2. Managing Plugins and Themes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Install, activate, deactivate, or delete plugins and themes without touching the dashboard.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Install and activate a plugin:&lt;/strong&gt; &lt;code&gt;wp plugin install woocommerce --activate&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Deactivate a plugin:&lt;/strong&gt; &lt;code&gt;wp plugin deactivate woocommerce&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Delete a theme:&lt;/strong&gt; &lt;code&gt;wp theme delete twentytwenty&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;3. Creating and Managing Users&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;With WP-CLI, we can create a user or even reset a password.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Create a new user:&lt;/strong&gt; &lt;code&gt;wp user create johndoe johndoe@example.com --role=author&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Reset a user's password:&lt;/strong&gt; &lt;code&gt;wp user reset-password johndoe&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4. Database Management&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Handle database tasks like export, import, or optimize it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Export the database:&lt;/strong&gt; &lt;code&gt;wp db export&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Import a database:&lt;/strong&gt; &lt;code&gt;wp db import backup.sql&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Optimize the database:&lt;/strong&gt; &lt;code&gt;wp db optimize&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;5. Search and Replace&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Perfect for site migrations, this command lets you update URLs or text across your database.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Search and replace URLs:&lt;/strong&gt; &lt;code&gt;wp search-replace 'http://old-domain.com' 'http://new-domain.com'&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;6. Managing Posts and Pages&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Create, edit, or delete content directly from the terminal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a new page:&lt;/strong&gt; &lt;code&gt;wp post create --post_type=page --post_title='About Us' --post_status=publish&lt;/code&gt;\&lt;br&gt;
&lt;strong&gt;Delete a post:&lt;/strong&gt; &lt;code&gt;wp post delete 123 --force&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;7. Running Cron Jobs&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Manually trigger or manage WordPress cron jobs without waiting for scheduled events.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Run all cron events:&lt;/strong&gt; &lt;code&gt;wp cron event run --all&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;List scheduled cron events:&lt;/strong&gt; &lt;code&gt;wp cron event list&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;8. Generating Dummy Data&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Generate dummy content to test your site.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Generate 10 dummy posts:&lt;/strong&gt; &lt;code&gt;wp post generate --count=10&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Generate 5 dummy users:&lt;/strong&gt; &lt;code&gt;wp user generate --count=5&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;9. Managing Multisite Installations&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;For WordPress Multisite users, WP-CLI simplifies network-wide management.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Create a new site:&lt;/strong&gt; &lt;code&gt;wp site create --slug=newsite&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;List all sites in the network:&lt;/strong&gt; &lt;code&gt;wp site list&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;WP-CLI transforms WordPress management by offering a fast, efficient alternative to the dashboard. From automating updates to managing multisite networks, it saves time, reduces errors, and lets you focus on what matters most. Run &lt;code&gt;wp help&lt;/code&gt; for a list of commands or explore the &lt;a href="https://developer.wordpress.org/cli/commands/" rel="noopener noreferrer"&gt;https://developer.wordpress.org/cli/commands/&lt;/a&gt; for more commands and options.&lt;/p&gt;

&lt;p&gt;If you like this article, share it with your friends and colleagues. Comment below with your feedback, suggestions or just to say "Hi"!&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>wpcli</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How a Browser Works: DNS, HTTP Request, DOM, CSSOM</title>
      <dc:creator>Ashik</dc:creator>
      <pubDate>Sun, 20 Apr 2025 04:19:01 +0000</pubDate>
      <link>https://forem.com/ashikrnhq04/how-a-browser-works-dns-http-request-dom-cssom-50kc</link>
      <guid>https://forem.com/ashikrnhq04/how-a-browser-works-dns-http-request-dom-cssom-50kc</guid>
      <description>&lt;p&gt;Understanding how browsers work is a game-changer to become a better developer, problem solver, and all-around tech badass.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step-by-Step: How the Browser Works
&lt;/h2&gt;

&lt;p&gt;1. When we hit a domain e.g. codespoetry.com, the browser looks for DNS resolution. So, it goes through a DNS lookup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Browser Cache&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;OS Cache&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Router&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ISP DNS server&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Authoritative DNS server&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In case of a valid domain, the domain is resolved to an IP address like 123.12.13.14&lt;/p&gt;

&lt;p&gt;2. Then the browser makes an HTTP/HTTPS request and opens a TCP connection (or TLS for HTTPS). The HTTP request contains some necessary info as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET / HTTP/1.1
Host: codespoetry.com
User-Agent: Chrome/123.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3. After receiving the HTTP/HTTPS request, the server responds with an HTML Document:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/1.1 200 OK
Content-Type: text/html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Welcome&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;Hello world&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4. The Browser starts rendering HTML, and this contains a few steps:&lt;/p&gt;

&lt;h3&gt;
  
  
  Parsing the DOM
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;HTML is parsed top to bottom.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tags become nodes in a tree (DOM)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Assets are fetched (CSS, JS, Images)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The browser pauses HTML parsing when it finds a stylesheet ( or script ( unless defer or async is used) since those are render blocking.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;DOM construction is incremental. The HTML response turns into tokens, which turn into nodes, which turn into the DOM Tree. A single DOM node starts with a startTag token and ends with an endTag token. Nodes contain all relevant information about the HTML element. The information is described using tokens. Nodes are connected into a DOM tree based on the token hierarchy. If another set of startTag and endTag tokens comes between a set of startTag and endTags, you have a node inside a node, which is how we define the hierarchy of the DOM tree.&lt;/p&gt;

&lt;p&gt;Note: The script with the defer attribute downloads the script in parallel with HTML parsing, but executes after finishing the parsing of HTML. And a script with the async attribute executes immediately after download finishes – even if the HTML is still being parsed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Style Calculation: CSSOM
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;CSS is parsed into another tree called CSSOM, similar to the DOM&lt;/li&gt;
&lt;li&gt;DOM and CSSOM are merged into the render tree&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The DOM contains all the content of the page. The CSSOM contains all the information on how to style the DOM. CSSOM is similar to the DOM, but different. While the DOM construction is incremental, CSSOM is not. CSS is render blocking: the browser blocks page rendering until it receives and processes all the CSS. CSS is render-blocking because rules can be overwritten, so the content can’t be rendered until the CSSOM is complete. The render tree captures both the content and the styles: the DOM and CSSOM trees are combined into the render tree. To construct the render tree, the browser checks every node, starting from the root of the DOM tree, and determines which CSS rules are attached.&lt;/p&gt;
&lt;p&gt;Here is &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Performance/Guides/Critical\_rendering\_path" rel="noopener noreferrer"&gt;MDN &lt;/a&gt;reference to know more about the rendering path.&lt;/p&gt;

&lt;h3&gt;
  
  
  Layout
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Each node is given coordinates (where it appears in the viewport)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Painting
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Nodes are drawn on the screen pixel by pixel&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Composition
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Browser layers things (like z-index, transforms etc) and paints them efficiently&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now the actual first render happens, and we see something on the screen.&lt;/p&gt;

&lt;p&gt;5. JavaScript Execution&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Browser parses and runs JS&lt;/li&gt;
&lt;li&gt;JS can:

&lt;ul&gt;
&lt;li&gt;Change the DOM&lt;/li&gt;
&lt;li&gt;Respond to user events (clicks, inputs)&lt;/li&gt;
&lt;li&gt;Make new network requests (AJAX/fetch)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Here, I wrote an article on &lt;a href="https://codespoetry.com/javascript-execution-context-call-stack-web-apis-and-event-loop/" rel="noopener noreferrer"&gt;JavaScript execution context&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;6. Ongoing stuff&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User interacts&lt;/li&gt;
&lt;li&gt;Event trigger&lt;/li&gt;
&lt;li&gt;DOM changes&lt;/li&gt;
&lt;li&gt;CSS changes&lt;/li&gt;
&lt;li&gt;Browser re-calculates layout/paint&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Render Flow Visualized:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;URL → DNS → HTTP Request → HTML Response
     ↓
Parse HTML → DOM Tree
     ↓
Fetch CSS → CSSOM Tree
     ↓
DOM + CSSOM → Render Tree
     ↓
Layout → Paint → Composite → Show on Screen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All this work is produced and processed by Browser Engines. Here are the Key Browser Engines under the hood.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Browser&lt;/th&gt;
&lt;th&gt;Engine&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Chrome, Edge&lt;/td&gt;
&lt;td&gt;Blink + V8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Firefox&lt;/td&gt;
&lt;td&gt;Gecko + SpiderMoneky&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Safari&lt;/td&gt;
&lt;td&gt;Webkit + JavaScriptCore&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Here is the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Performance/Guides/How_browsers_work" rel="noopener noreferrer"&gt;MDN&lt;/a&gt; reference on how browsers work and a deep dive.&lt;/p&gt;

&lt;p&gt;I hope this article will help you to understand what's going on behind the certain (Browser). Please share the article and leave your feedback, suggestions whatever in the comment box below.&lt;/p&gt;

</description>
      <category>browser</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>JavaScript DOM Manipulation</title>
      <dc:creator>Ashik</dc:creator>
      <pubDate>Sat, 12 Apr 2025 21:02:12 +0000</pubDate>
      <link>https://forem.com/ashikrnhq04/javascript-dom-manipulation-2998</link>
      <guid>https://forem.com/ashikrnhq04/javascript-dom-manipulation-2998</guid>
      <description>&lt;p&gt;I wrote this post on my blog &lt;a href="https://codespoetry.com/javascript-dom-manipulation/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Initially, JavaScript was built to manipulate the DOM and capture user interaction. Nowadays, JavaScript is far from that and has established itself as a powerful cross-platform language. Although the old-school method may not be as popular in the modern era of React, Vue, and other libraries, it still has a place. Learning DOM manipulation helps developers understand how frameworks manage and update the DOM efficiently (e.g., React's virtual DOM).&lt;/p&gt;

&lt;p&gt;It's invaluable for debugging or enhancing legacy systems that rely heavily on direct DOM access.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is DOM
&lt;/h2&gt;

&lt;p&gt;The DOM, the Document Object Model, is a tree view of a page's HTML structure. If we check a page's source code, we see many nodes in parent-child relations. That's the DOM.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is DOM Manipulation
&lt;/h2&gt;

&lt;p&gt;The DOM manipulation uses JavaScript to add, remove, and modify the HTML structure. We may need it to apply CSS, add attributes, remove/show/hide an element based on user interaction, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  DOM Manipulation
&lt;/h2&gt;

&lt;p&gt;I will start by creating an element and manipulating it into a document.&lt;/p&gt;

&lt;p&gt;Let's assume we have a document with only a body tag, and we'll add a few elements to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;

&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//creation of a div element and add class
const divElement = document.createElement("div");
divElement.classList.add("container");

//creation of a heading element add text
const heading = document.createElement("h1");
heading.textContent = "Hello ";

//creation of a span element and add class and text, set text color of the span
const span = document.createElement("span");
span.classList.add("highlight");
span.style.color = "red";
span.textContent = "World";

//creation of a heading2 element and add text
const heading2 = document.createElement("h2");
heading2.textContent = "Hello World 2";

//appending span element to the heading element
heading.appendChild(span);

//appending heading to the div element and span element to the heading element
divElement.append(heading, heading2);

//appending div element to the body
document.body.append(divElement);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To insert element, I used both the &lt;code&gt;append&lt;/code&gt; and &lt;code&gt;appendChild&lt;/code&gt; methods. There are subtle differences between them.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;append&lt;/code&gt; is newer and more versatile, supporting text nodes and multiple elements, while &lt;code&gt;appendChild&lt;/code&gt; is older and more limited. So, in place of &lt;code&gt;textContent&lt;/code&gt;, we can use &lt;code&gt;append&lt;/code&gt; to add text but not the &lt;code&gt;appendChild&lt;/code&gt; method. An example will come later in this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some selection methods
&lt;/h2&gt;

&lt;p&gt;In the above code example, we selected the &lt;code&gt;body&lt;/code&gt; tag using a pre-defined way of document. So, by writing &lt;code&gt;document.body&lt;/code&gt;, we got access to the &lt;code&gt;body&lt;/code&gt; tag. But what if we need to select a different element?&lt;/p&gt;

&lt;p&gt;Here are 2 common ways to select elements.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; document.querySelector();&lt;/li&gt;
&lt;li&gt; document.querySelectorAll()&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Both methods accept a string as a parameter. The querySelector() method will return the element as the node we want to select.&lt;/p&gt;

&lt;p&gt;The querySelectorAll() method returns a Node List containing all the matched elements. A Node List is similar to an Array.&lt;/p&gt;

&lt;p&gt;We can pass the selector to the above methods, like ".myElement," "#myElement," or "h1." Class, ID, or element tags will work as selectors.&lt;/p&gt;

&lt;h2&gt;
  
  
  Something Complex
&lt;/h2&gt;

&lt;p&gt;We'll check the above 2 methods of selecting elements to see if they actually work and try some complex manipulation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//select the span element
const spanElement = document.querySelector(".highlight");

//create a new span element and add text to it
const spanElement2 = document.createElement("span");
spanElement2.append("Colorful ");

//insert the new span element before the existing span element
heading.insertBefore(spanElement2, spanElement);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we used &lt;code&gt;querySelector&lt;/code&gt; method to select the span element and class is our selector here. We can also use "span" as a selector or element ID (if any). These two methods also support nesting selection, like &lt;code&gt;document.querySelector(".highlight .myCustomClass")&lt;/code&gt;. This will select the element with the class &lt;code&gt;myCustomClass&lt;/code&gt; inside the &lt;code&gt;.highlight&lt;/code&gt; element.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;insertBefore&lt;/code&gt; method is used to insert an element exactly before the referenced element. So, the code is now like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
  &amp;lt;div class="container"&amp;gt;
    &amp;lt;h1&amp;gt;
      Hello &amp;lt;span&amp;gt;Colorful &amp;lt;/span&amp;gt;
      &amp;lt;span class="highlight" style="color: red"&amp;gt;World&amp;lt;/span&amp;gt;
    &amp;lt;/h1&amp;gt;
    &amp;lt;h2&amp;gt;Hello World 2&amp;lt;/h2&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: If there is no referenced element, the new element will be inserted as the last child of the container/parent element.&lt;/p&gt;

&lt;h2&gt;
  
  
  More selection methods
&lt;/h2&gt;

&lt;p&gt;There are a few more ways to select an element.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; document.getElementById()&lt;/li&gt;
&lt;li&gt; document.getElementsByTags()&lt;/li&gt;
&lt;li&gt; document.getElementsByClassName()&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;code&gt;getElementById()&lt;/code&gt; method can select a single element by ID. The other two methods will return a collection of nodes (if available) as NodeList.&lt;/p&gt;

&lt;p&gt;While the querySelector and querySelectorAll methods are modern and more flexible, these three methods are faster for performance-sensitive tasks.&lt;/p&gt;

&lt;h2&gt;
  
  
  The innerHTML method
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;innerHTML&lt;/code&gt; is commonly used to insert elements into DOM. This method treats everything as text even though you insert a node. Also, this method replace everything within the Node you're inserting in.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;innerHTML&lt;/code&gt; can introduce security risks when working with user input (e.t., cross-site scripting);&lt;/p&gt;

&lt;h2&gt;
  
  
  Set attributes DOM manipulation
&lt;/h2&gt;

&lt;p&gt;Now we know how to select an element and manipulate DOM. JavaScript provides &lt;code&gt;setAttributes method to set a&lt;/code&gt; custom attribute to an element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//select the highlighted span element by classname
const highlightedElement = document.getElementByClassName("highlight")[0];

//set a custom attribute
highlightedElement.setAttribute("data-site", "codespoetry.com");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we selected an element by ClassName. Since this method returns a collection of nodes even if only one element exists, I used the index [0] to select the first element. We can use the index to select a specific element in case of multiple elements with the same class or tag.&lt;/p&gt;

&lt;p&gt;One thing to note here, we can set any name as an attribute property. However, using data-[custom name] gives us the flexibility of accessing that attribute by &lt;code&gt;highlightElement.dataset.site&lt;/code&gt;. So we don't need to use the &lt;code&gt;getAttribute&lt;/code&gt; method to access an attribute.&lt;/p&gt;

&lt;p&gt;Similar to setAttribute, there is another method &lt;code&gt;removeAttribute&lt;/code&gt;() to remove an attribute from an element.&lt;/p&gt;

&lt;p&gt;I hope this article will help you learn and understand JavaScript DOM manipulation. Please share the article and leave feedback and suggestions in the comment box below.&lt;/p&gt;

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