<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rakhi Singh</title>
    <description>The latest articles on DEV Community by Rakhi Singh (@rakhee).</description>
    <link>https://dev.to/rakhee</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%2F2057595%2F29a082e2-0725-43db-9e5a-eb8f51c6251a.jpeg</url>
      <title>DEV Community: Rakhi Singh</title>
      <link>https://dev.to/rakhee</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rakhee"/>
    <language>en</language>
    <item>
      <title>Best Practices to Optimize a Video Streaming Platform</title>
      <dc:creator>Rakhi Singh</dc:creator>
      <pubDate>Sat, 01 Feb 2025 07:29:21 +0000</pubDate>
      <link>https://dev.to/rakhee/system-design-optimizing-video-streaming-performance-and-user-experience-1i9k</link>
      <guid>https://dev.to/rakhee/system-design-optimizing-video-streaming-performance-and-user-experience-1i9k</guid>
      <description>&lt;p&gt;Streaming high-quality video efficiently is a challenge that requires careful optimization. Whether you're building a custom video player or handling large media files, optimizing video playback can &lt;strong&gt;significantly improve user experience&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this post, we'll explore &lt;strong&gt;best practices&lt;/strong&gt; for improving video streaming performance, from buffering optimization to adaptive resolution management. Let's dive in! 🎬&lt;/p&gt;




&lt;p&gt;Before starting the discussion let's assume that we are getting video streaming API response in this format.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "bitrates": {
    "1080p": "https://your-server.com/videos/1080p/",
    "720p": "https://your-server.com/videos/720p/",
    "480p": "https://your-server.com/videos/480p/"
  },
  "chunks": ["chunk0.mp4", "chunk1.mp4", "chunk2.mp4"] 
}

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  1️⃣ Why Not Just Use the &lt;code&gt;&amp;lt;video&amp;gt;&lt;/code&gt; Tag? 🤔
&lt;/h2&gt;

&lt;p&gt;When you think of a video player, the first thing that comes to mind is the &lt;code&gt;&amp;lt;video&amp;gt;&lt;/code&gt; element. But &lt;strong&gt;this approach has limitations&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;Works well for short videos&lt;/strong&gt; that can be downloaded in one go.&lt;br&gt;&lt;br&gt;
❌ &lt;strong&gt;Inefficient for long videos&lt;/strong&gt; (e.g., movies or live streams) because it requires downloading the full file upfront.&lt;br&gt;&lt;br&gt;
❌ &lt;strong&gt;No control over buffering &amp;amp; resolution&lt;/strong&gt; based on network conditions.&lt;/p&gt;
&lt;h3&gt;
  
  
  ✅ Better Approch: Media Source API (MSE)
&lt;/h3&gt;

&lt;p&gt;The Media Source API (MSE) allows dynamic buffering, adaptive streaming, and smooth resolution changes based on real-time network conditions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Does It Work? (Basic Setup)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here’s how we can use MSE to stream video dynamically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;video&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"videoPlayer"&lt;/span&gt; &lt;span class="na"&gt;controls&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/video&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;video&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;videoPlayer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mediaSource&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MediaSource&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;video&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createObjectURL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mediaSource&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;mediaSource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sourceopen&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;bitrates&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;chunks&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetchManifest&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;resolution&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getOptimalResolution&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nf"&gt;fetchAndAppendChunks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mediaSource&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;bitrates&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;resolution&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fetchManifest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://your-server.com/manifest.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This script:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fetches &lt;strong&gt;available video resolutions&lt;/strong&gt; (from a JSON manifest file).&lt;/li&gt;
&lt;li&gt;Selects the &lt;strong&gt;best resolution&lt;/strong&gt; based on network speed.&lt;/li&gt;
&lt;li&gt;Loads video chunks &lt;strong&gt;dynamically&lt;/strong&gt; instead of downloading everything at once.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2️⃣ Optimizing Video Loading &amp;amp; Buffering 🚀
&lt;/h2&gt;

&lt;p&gt;Ever noticed how &lt;strong&gt;Netflix &amp;amp; YouTube&lt;/strong&gt; start playing videos instantly? They use &lt;strong&gt;chunk-based loading&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;Divides video into small chunks&lt;/strong&gt; 🔹🔹🔹&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Loads only a few chunks initially&lt;/strong&gt; (for instant playback)&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Fetches additional chunks on demand&lt;/strong&gt; (as the video progresses)  &lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Implementation&lt;/strong&gt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fetchAndAppendChunks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mediaSource&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;baseUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sourceBuffer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mediaSource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addSourceBuffer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;video/mp4; codecs="avc1.64001E, mp4a.40.2"&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;chunkIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;appendNextChunk&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;chunkIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;mediaSource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;endOfStream&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;baseUrl&lt;/span&gt;&lt;span class="p"&gt;}${&lt;/span&gt;&lt;span class="nx"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;chunkIndex&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chunk&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;arrayBuffer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;sourceBuffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendBuffer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;chunkIndex&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;sourceBuffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;updateend&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;appendNextChunk&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;once&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;appendNextChunk&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3️⃣ Managing Resolution Automatically 📶
&lt;/h2&gt;

&lt;p&gt;Streaming services &lt;strong&gt;adjust video resolution based on available bandwidth&lt;/strong&gt; to prevent buffering.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getOptimalResolution&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;downlink&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Get network speed in Mbps&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1080p&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;720p&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;480p&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ &lt;strong&gt;Monitors internet speed&lt;/strong&gt; 📶&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Automatically switches resolution&lt;/strong&gt; to prevent lag&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Ensures smooth playback&lt;/strong&gt; even on slow networks  &lt;/p&gt;


&lt;h2&gt;
  
  
  4️⃣ Separating Video &amp;amp; Audio for Better Control 🎵🎥
&lt;/h2&gt;

&lt;p&gt;For a better user experience, &lt;strong&gt;separate video and audio streams&lt;/strong&gt;. This allows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Multi-language support&lt;/strong&gt;: Users can switch audio tracks without restarting the video.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adaptive audio streaming&lt;/strong&gt;: Loads only the necessary audio based on network conditions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔹 &lt;strong&gt;Advanced use case&lt;/strong&gt;: Load separate &lt;code&gt;audio.mp4&lt;/code&gt; and &lt;code&gt;video.mp4&lt;/code&gt; files using &lt;strong&gt;multiple SourceBuffers&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  5️⃣ Caching Video Data for Faster Playback 🔄
&lt;/h2&gt;

&lt;p&gt;Caching reduces unnecessary API calls and speeds up video loading.&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;Use Service Workers &amp;amp; Cache API&lt;/strong&gt; to store video chunks.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Implement LRU (Least Recently Used) caching&lt;/strong&gt; to discard old video chunks.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Enable offline playback&lt;/strong&gt; by caching frequently accessed content.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fetch&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;respondWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;caches&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;video-cache&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clone&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






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

&lt;p&gt;Optimizing video streaming is &lt;strong&gt;crucial for a smooth user experience&lt;/strong&gt;. By using &lt;strong&gt;chunk-based loading, adaptive streaming, caching, and MSE&lt;/strong&gt;, we can build highly efficient video players.&lt;/p&gt;

&lt;h3&gt;
  
  
  🚀 Key Takeaways
&lt;/h3&gt;

&lt;p&gt;✅ Use &lt;strong&gt;MSE instead of &lt;code&gt;&amp;lt;video&amp;gt;&lt;/code&gt; for long videos&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
✅ Implement &lt;strong&gt;chunk-based loading&lt;/strong&gt; for fast startup&lt;br&gt;&lt;br&gt;
✅ Dynamically &lt;strong&gt;adjust resolution based on network speed&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
✅ Cache video data to &lt;strong&gt;reduce reloading &amp;amp; improve performance&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;What other optimizations do you use for video streaming? Share your thoughts in the comments! 🎥✨&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Top 10 Practices to make your app accessible</title>
      <dc:creator>Rakhi Singh</dc:creator>
      <pubDate>Sat, 18 Jan 2025 11:52:42 +0000</pubDate>
      <link>https://dev.to/rakhee/accessibility-its-more-than-just-alt-text-44c5</link>
      <guid>https://dev.to/rakhee/accessibility-its-more-than-just-alt-text-44c5</guid>
      <description>&lt;p&gt;Early in my career, I thought accessibility was simple. I believed it was only for people with disabilities and that it mostly happened automatically. My understanding was basically:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Add alt text to images &lt;code&gt;&amp;lt;img/&amp;gt;&lt;/code&gt; tags and you're done!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But now, as a more experienced software engineer, I see accessibility differently. First of all, accessibility is for everybody. When a user wants to submit a form, they should be able to press the Enter key instead of hunting for the submit button. Accessibility isn’t just about compliance; it’s about creating seamless, enjoyable experiences for everyone.&lt;/p&gt;

&lt;p&gt;Accessibility is not just about adding a few lines of code. It's a fundamental part of software development and an architectural decision we must make while developing a simple button or Table on the app.&lt;/p&gt;

&lt;h3&gt;
  
  
  My Top 10 Accessibility Practices
&lt;/h3&gt;

&lt;p&gt;Here are my top 10 accessibility practices that I implement in every app I build:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Use Semantic Elements&lt;/strong&gt;&lt;br&gt;
  Use proper HTML5 semantic elements like &lt;code&gt;&amp;lt;header&amp;gt;, &amp;lt;nav&amp;gt;, &amp;lt;article&amp;gt;, &amp;lt;button&amp;gt;,  &amp;lt;footer&amp;gt;&lt;/code&gt;. These elements provide context to screen readers and improve navigation for users.&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;header&amp;gt;
    &amp;lt;h1&amp;gt;App Title&amp;lt;/h1&amp;gt;
&amp;lt;/header&amp;gt;
&amp;lt;nav&amp;gt;
    &amp;lt;ul&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href="/home"&amp;gt;Home&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href="/about"&amp;gt;About&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
    &amp;lt;/ul&amp;gt;
&amp;lt;/nav&amp;gt;
&amp;lt;article&amp;gt;
    &amp;lt;p&amp;gt;This is the main content.&amp;lt;/p&amp;gt;
&amp;lt;/article&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Add Keyboard Controls&lt;/strong&gt;&lt;br&gt;
Ensure users can navigate your app using just the keyboard. For example, they should be able to move between pages or features using Tab, Arrow keys, or other intuitive keyboard shortcuts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.addEventListener('keydown', (event) =&amp;gt; {
    if (event.key === 'ArrowRight') {
        moveToNextTab();
    } else if (event.key === 'ArrowLeft') {
        moveToPreviousTab();
    }
});

function moveToNextTab() {
    // Logic to focus the next tab
}

function moveToPreviousTab() {
    // Logic to focus the previous tab
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Use ARIA Labels Wisely&lt;/strong&gt;&lt;br&gt;
Add ARIA (aria-label, aria-labelledby, etc.) attributes to elements when necessary, but don’t overuse them. Prefer semantic HTML first.&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;button aria-label="Close Modal"&amp;gt;X&amp;lt;/button&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Add alt Attributes to Images&lt;/strong&gt;&lt;br&gt;
Every &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; element should have an alt attribute that describes the image—or use alt="" for decorative images.&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;img src="profile.jpg" alt="User Profile Picture" /&amp;gt;
&amp;lt;img src="decorative-line.png" alt="" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Enable Table Navigation with Keyboard&lt;/strong&gt;&lt;br&gt;
For &lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt; elements, ensure users can navigate rows and columns using the Arrow keys.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const table = document.querySelector('table');
table.addEventListener('keydown', (event) =&amp;gt; {
    const currentCell = document.activeElement;
    if (event.key === 'ArrowDown') {
        moveFocus(currentCell, 'down');
    } else if (event.key === 'ArrowUp') {
        moveFocus(currentCell, 'up');
    }
});

function moveFocus(cell, direction) {
    // Logic to shift focus to the appropriate cell
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Manage Focus Effectively&lt;/strong&gt;&lt;br&gt;
Decide where the focus should land when a page loads or a modal opens. For example, when you open any editable app the focus first should go to the editor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function openModal() {
    const modal = document.querySelector('#modal');
    modal.style.display = 'block';
    modal.querySelector('input').focus(); // Focus on the first input field
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. Keyboard Controls for Media&lt;/strong&gt;&lt;br&gt;
Implement keyboard controls for play/pause, volume adjustments, and seeking forward or backward.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const video = document.querySelector('video');
document.addEventListener('keydown', (event) =&amp;gt; {
    if (event.key === ' ') {
        video.paused ? video.play() : video.pause();
    } else if (event.key === 'ArrowRight') {
        video.currentTime += 5; // Seek forward 5 seconds
    } else if (event.key === 'ArrowLeft') {
        video.currentTime -= 5; // Seek backward 5 seconds
    }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;8. Accessible Forms&lt;/strong&gt;&lt;br&gt;
Ensure labels are associated with their inputs and provide helpful error messages or use autoComplete attribute of input element so that user doesn't have to type everything.&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;form&amp;gt;
    &amp;lt;label for="username"&amp;gt;Username:&amp;lt;/label&amp;gt;
    &amp;lt;input type="text" id="username" name="username" required /&amp;gt;
    &amp;lt;span class="error" id="username-error" aria-live="polite"&amp;gt;&amp;lt;/span&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;9. Color Contrast Matters&lt;/strong&gt;&lt;br&gt;
  Maintain a high color contrast ratio between text and background.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body {
    background-color: #ffffff;
    color: #000000;
}

.button {
    background-color: #007bff;
    color: #ffffff;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;10. Create a Design System&lt;/strong&gt;&lt;br&gt;
 When you start working on building an app, every time you can't think every time about accessibility you should build accessible atomic components once and reuse them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function AccessibleButton({ label, onClick }) {
    return (
        &amp;lt;button onClick={onClick} aria-label={label}&amp;gt;
            {label}
        &amp;lt;/button&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Accessibility is not an afterthought. It’s a mindset that should be embedded in your development process from the start. By making these practices a part of your workflow, you’ll create apps that are not only functional but also inclusive and user-friendly.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>designsystem</category>
      <category>architecture</category>
      <category>a11y</category>
    </item>
    <item>
      <title>Guide - Setting Up Jest for Unit Testing in a TypeScript React Project</title>
      <dc:creator>Rakhi Singh</dc:creator>
      <pubDate>Fri, 10 Jan 2025 17:26:38 +0000</pubDate>
      <link>https://dev.to/rakhee/guide-configuring-jest-unit-test-in-typescript-react-project-548j</link>
      <guid>https://dev.to/rakhee/guide-configuring-jest-unit-test-in-typescript-react-project-548j</guid>
      <description>&lt;p&gt;Recently, I got a chance to work on my first typescript project, and my first task was to set up unit test cases. At first glance, it seemed simple enough. I started following random documentation and ChatGPT suggestions, only to end up with a mess. If you’ve experienced GPT giving a solution only to later suggest removing it, you’ll relate to my frustration.&lt;/p&gt;

&lt;p&gt;After countless docs, GitHub issues, and a little frustration, I finally cracked the code and set up a clean, robust unit testing environment. 🎉&lt;/p&gt;

&lt;p&gt;And then I thought, “Why not document this to save future-me and fellow devs from the same struggle?” So, here it is:&lt;/p&gt;

&lt;p&gt;Here, I’ve written one more comprehensive guide on the internet to help fellow developers set up their first unit test environment in a TypeScript project—the right way.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 1: Install Required Libraries
&lt;/h3&gt;

&lt;p&gt;Start by installing the necessary libraries to set up a Jest environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-D&lt;/span&gt; @types/jest @types/react-dom @types/react ts-jest typescript @testing-library/jest-dom @testing-library/react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 2: Initialize &lt;code&gt;tsconfig.json&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Run the following command to create a &lt;code&gt;tsconfig.json&lt;/code&gt; file in your project’s root directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ts-jest config:init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 3: Configure &lt;code&gt;tsconfig.json&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Replace the content of your &lt;code&gt;tsconfig.json&lt;/code&gt; file with the following configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "compilerOptions": {
   "types": ["@testing-library/jest-dom", "node", "jest"],
    "module": "commonjs",
    "target": "es6",
    "outDir": "./dist",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "jsx": "react",  
    "lib": ["es2019", "dom"]  
  },
  "include": ["./src/**/**.*", "src/*.ts", "src/setupTests.tsx"]
  "exclude": ["node_modules"]
}

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

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 4: Configure Jest
&lt;/h3&gt;

&lt;p&gt;Replace the content of your &lt;code&gt;jest.config.js&lt;/code&gt; file with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;testEnvironment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;jest-environment-jsdom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;setupFilesAfterEnv&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;rootDir&amp;gt;/src/setupTests.tsx&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="c1"&gt;// Update the path if your setupTests file is located elsewhere&lt;/span&gt;
  &lt;span class="na"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;^.+&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;.tsx?$&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;babel-jest&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Or ts-jest if you're using ts-jest&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;moduleFileExtensions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tsx&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;jsx&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, create a &lt;code&gt;setupTests.tsx&lt;/code&gt; file in your &lt;code&gt;src&lt;/code&gt; folder and add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@testing-library/jest-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 5: Write Test Cases
&lt;/h3&gt;

&lt;p&gt;Create a test file, e.g., &lt;code&gt;YourComponent.test.tsx&lt;/code&gt;, in your project’s &lt;code&gt;tests&lt;/code&gt; folder. This is where you’ll write your unit test cases.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 6: Run Tests
&lt;/h3&gt;

&lt;p&gt;Run the following command to execute your tests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Personal Note - When you are working with Typescript you will see this below error &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Property 'toBeInTheDocument' does not exist on type 'JestMatchers&amp;lt;HTMLElement&amp;gt;'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To resolve I have already added configuration in the above code but If you still see the issue then &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Try importing this library @testing-library/jest-dom in all your test files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure that you have the correct Babel configuration. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Notes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Remember, this guide focuses on setting up the environment; you’ll need to figure out how to write the actual test cases based on your application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope this guide saves you the frustration I faced. Happy testing! 🚀&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>jest</category>
      <category>testing</category>
      <category>react</category>
    </item>
    <item>
      <title>Can React v19 replace React Query(Tanstack)?</title>
      <dc:creator>Rakhi Singh</dc:creator>
      <pubDate>Fri, 20 Dec 2024 11:56:53 +0000</pubDate>
      <link>https://dev.to/rakhee/can-react-v19-replace-react-querytanstack-5gmh</link>
      <guid>https://dev.to/rakhee/can-react-v19-replace-react-querytanstack-5gmh</guid>
      <description>&lt;p&gt;The React team has recently launched the stable version of React 19, bringing a host of new features and improvements that are set to revolutionize how we build React applications. &lt;br&gt;
While these updates aim to provide native solutions to common patterns and challenges in React development, one key question arises: do these new hooks have the potential to replace popular packages like Tanstack Query (formerly React Query)?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What’s New in React 19&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React 19 introduces several new hooks and features designed to simplify data handling, improve performance, and enhance developer experience. Here am going to a brief overview of some of the most notable changes that are common between React 19 and Tanstack :&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. useActionState&lt;/strong&gt; This hook helps manage common cases for actions, providing built-in support for handling errors, pending states, and form submissions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [error, submitAction, isPending] = useActionState(
  async (previousState, newName) =&amp;gt; {
    const error = await updateName(newName);
    if (error) return error;
    return null;
  },
  null
);

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. useFormStatus&lt;/strong&gt; This is a kind of game-changing hook, with no need for any context API, or props drilling, this hook allows components to access the form state of the Parent component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useFormStatus } from 'react-dom';

function DesignButton() {
  const { pending } = useFormStatus();
  return &amp;lt;button type="submit" disabled={pending}&amp;gt;Submit&amp;lt;/button&amp;gt;;
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. useOptimistic&lt;/strong&gt; Another common UI pattern when performing a data mutation is to show the final state optimistically while the async request is underway.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function ChangeName({ currentName, onUpdateName }) {
  const [optimisticName, setOptimisticName] = useOptimistic(currentName);

  const submitAction = async (formData) =&amp;gt; {
    const newName = formData.get("name");
    setOptimisticName(newName);
    const updatedName = await updateName(newName);
    onUpdateName(updatedName);
  };

  return (
    &amp;lt;form action={submitAction}&amp;gt;
      &amp;lt;p&amp;gt;Your name is: {optimisticName}&amp;lt;/p&amp;gt;
      &amp;lt;label&amp;gt;Change Name:&amp;lt;/label&amp;gt;
      &amp;lt;input type="text" name="name" disabled={currentName !== optimisticName} /&amp;gt;
    &amp;lt;/form&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Now, you might be thinking, "Do I need Tanstack Query for my async handlers?" Well, the answer is: it depends on your use case! Let's understand HOW ?😅
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Why and When to Choose React Query for Complex Scenarios?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advanced Caching:&lt;/strong&gt; React Query provides robust caching mechanisms that can handle complex data structures and keep your application in sync with the server state effortlessly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Automatic Background Synchronization:&lt;/strong&gt;  It supports background refetching, polling, and refetching on events like window focus, ensuring the data is always up-to-date. No more stale data 🔄&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Query Invalidations:&lt;/strong&gt; React Query allows developers to manage when and how your data should be refreshed, ensuring that your UI is always up-to-date without unnecessary re-fetches. 🎯&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Error Handling:&lt;/strong&gt; It provides a comprehensive approach to handle errors gracefully, making your application more resilient. 🚑&lt;/p&gt;

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

&lt;p&gt;In the end, I guess you have already got the answer to the question we raised at the beginning - Can React v19 replace Tanstack? 🤔&lt;/p&gt;

&lt;p&gt;It completely depends on our application scale! 🏗️&lt;/p&gt;

&lt;p&gt;For simpler use cases, like fetching API data and managing API states, I would recommend giving React v19's native hooks a try. They are neat, easy to use, and perfect for straightforward scenarios. 🌟&lt;/p&gt;

&lt;p&gt;However, if you are working on a large application and need to handle more complex tasks like caching, revalidating, and synchronizing data with the server, then Tanstack Query is your best buddy! 🦸‍♂️🦸‍♀️&lt;/p&gt;

&lt;p&gt;In summary:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://react.dev/blog/2024/12/05/react-19" rel="noopener noreferrer"&gt;React v19 hooks&lt;/a&gt;: Great for simple API fetching and state management. 👍&lt;br&gt;
&lt;a href="https://tanstack.com/query/latest" rel="noopener noreferrer"&gt;Tanstack Query&lt;/a&gt;: Perfect for handling caching, synchronization, and complex data scenarios. 💪&lt;br&gt;
Happy coding! 🎉✨&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>discuss</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>test</title>
      <dc:creator>Rakhi Singh</dc:creator>
      <pubDate>Fri, 20 Dec 2024 06:07:28 +0000</pubDate>
      <link>https://dev.to/rakhee/uuu-e0o</link>
      <guid>https://dev.to/rakhee/uuu-e0o</guid>
      <description></description>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>How to Create a React Application Post-CRA Deprecation</title>
      <dc:creator>Rakhi Singh</dc:creator>
      <pubDate>Fri, 20 Dec 2024 06:03:31 +0000</pubDate>
      <link>https://dev.to/rakhee/how-to-create-a-react-application-post-cra-deprecation-3cdh</link>
      <guid>https://dev.to/rakhee/how-to-create-a-react-application-post-cra-deprecation-3cdh</guid>
      <description>&lt;p&gt;I was recently working on a project and learned that the React team deprecated create-react-app two years back. Initially, I didn't buy it But when I went to the new React-dev website, I noticed forgot about CRA they haven't mentioned how to create a simple React+bundler App&lt;/p&gt;

&lt;p&gt;Create a React App Without CRA: Using Vite or Webpack&lt;br&gt;
Since the React team deprecated create-react-app (CRA), developers are looking for alternative ways to set up their React applications. Two popular choices are Vite and Webpack. In this post, we will compare these tools and provide basic setup instructions for each.&lt;/p&gt;

&lt;p&gt;Vite vs. Webpack&lt;br&gt;
Vite&lt;br&gt;
Pros:&lt;br&gt;
Fast development server with instant hot module replacement (HMR).&lt;br&gt;
Built-in support for modern JavaScript features.&lt;br&gt;
Minimal configuration needed to get started.&lt;br&gt;
Cons:&lt;br&gt;
Newer tool, so it may have less community support compared to Webpack.&lt;br&gt;
Webpack&lt;br&gt;
Pros:&lt;br&gt;
Highly configurable and flexible for complex build setups.&lt;br&gt;
Extensive plugin ecosystem and community support.&lt;br&gt;
Proven track record with many large-scale applications.&lt;br&gt;
Cons:&lt;br&gt;
Initial configuration can be more complex and time-consuming.&lt;br&gt;
Slower build times compared to Vite.&lt;br&gt;
Setting Up a React App with Vite&lt;br&gt;
Create a New Vite Project:&lt;/p&gt;

&lt;p&gt;npm create vite@latest my-react-app -- --template react&lt;br&gt;
cd my-react-app&lt;br&gt;
npm install&lt;br&gt;
Start the Development Server:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
Copy code&lt;br&gt;
npm run dev&lt;br&gt;
Vite Configuration:&lt;/p&gt;

&lt;p&gt;Vite requires minimal configuration out of the box. The default setup should work for most React projects.&lt;br&gt;
You can customize the vite.config.js if needed.&lt;br&gt;
Setting Up a React App with Webpack&lt;br&gt;
Initialize Your Project:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
Copy code&lt;br&gt;
mkdir my-react-app&lt;br&gt;
cd my-react-app&lt;br&gt;
npm init -y&lt;br&gt;
npm install react react-dom&lt;br&gt;
npm install webpack webpack-cli webpack-dev-server html-webpack-plugin babel-loader &lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/core &lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-env &lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-react&lt;br&gt;
Create Project Structure:&lt;/p&gt;

&lt;p&gt;Create a src folder and add index.js and App.js files.&lt;br&gt;
Create a public folder and add an index.html file.&lt;br&gt;
Configure Webpack:&lt;/p&gt;

&lt;p&gt;Create a webpack.config.js file:&lt;br&gt;
javascript&lt;br&gt;
Copy code&lt;br&gt;
const path = require('path');&lt;br&gt;
const HtmlWebpackPlugin = require('html-webpack-plugin');&lt;/p&gt;

&lt;p&gt;module.exports = {&lt;br&gt;
  entry: './src/index.js',&lt;br&gt;
  output: {&lt;br&gt;
    path: path.resolve(&lt;strong&gt;dirname, 'dist'),&lt;br&gt;
    filename: 'bundle.js',&lt;br&gt;
  },&lt;br&gt;
  module: {&lt;br&gt;
    rules: [&lt;br&gt;
      {&lt;br&gt;
        test: /.(js|jsx)$/,&lt;br&gt;
        exclude: /node_modules/,&lt;br&gt;
        use: {&lt;br&gt;
          loader: 'babel-loader',&lt;br&gt;
        },&lt;br&gt;
      },&lt;br&gt;
      {&lt;br&gt;
        test: /.css$/,&lt;br&gt;
        use: ['style-loader', 'css-loader'],&lt;br&gt;
      },&lt;br&gt;
    ],&lt;br&gt;
  },&lt;br&gt;
  resolve: {&lt;br&gt;
    extensions: ['.js', '.jsx'],&lt;br&gt;
  },&lt;br&gt;
  plugins: [&lt;br&gt;
    new HtmlWebpackPlugin({&lt;br&gt;
      template: './public/index.html',&lt;br&gt;
    }),&lt;br&gt;
  ],&lt;br&gt;
  devServer: {&lt;br&gt;
    contentBase: path.join(&lt;/strong&gt;dirname, 'dist'),&lt;br&gt;
    compress: true,&lt;br&gt;
    port: 9000,&lt;br&gt;
  },&lt;br&gt;
};&lt;br&gt;
Babel Configuration:&lt;/p&gt;

&lt;p&gt;Create a .babelrc file:&lt;br&gt;
json&lt;br&gt;
Copy code&lt;br&gt;
{&lt;br&gt;
  "presets": ["&lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-env", "&lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-react"]&lt;br&gt;
}&lt;br&gt;
Start the Development Server:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
Copy code&lt;br&gt;
npx webpack serve&lt;br&gt;
Conclusion&lt;br&gt;
Both Vite and Webpack offer powerful ways to set up a React application without CRA. Vite provides a faster and simpler setup, ideal for smaller projects and rapid development. Webpack, on the other hand, offers extensive configurability and a robust ecosystem, making it suitable for more complex projects.&lt;/p&gt;

&lt;p&gt;Choose the tool that best fits your project requirements and preferences. Happy coding!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webpack</category>
      <category>vite</category>
    </item>
    <item>
      <title>How to Create a React Application Post-CRA Deprecation</title>
      <dc:creator>Rakhi Singh</dc:creator>
      <pubDate>Thu, 19 Dec 2024 04:39:05 +0000</pubDate>
      <link>https://dev.to/rakhee/how-to-create-a-react-application-post-cra-deprecation-19jl</link>
      <guid>https://dev.to/rakhee/how-to-create-a-react-application-post-cra-deprecation-19jl</guid>
      <description>&lt;p&gt;Hey there, fellow developers! 👋&lt;/p&gt;

&lt;p&gt;I was recently working on a project and learned that the React team deprecated create-react-app (CRA) two years ago. 😲 Naturally, this got me thinking about alternative ways to set up a JavaScript-based React application.&lt;/p&gt;

&lt;p&gt;When I checked out the official React documentation, I noticed they now focus on full-stack frameworks like Next.js and Gatsby. These are awesome if you’re building an end-to-end application, but they can be overkill if you just want a simple JSX-based project. 🏗️&lt;/p&gt;

&lt;p&gt;Before starting - What does CRA do? - Create React App (CRA) is a powerful package that automates the setup of a new React project. It handles all the necessary configuration and installs the required dependencies, providing a zero-configuration bundler. This allows developers to start building their applications without worrying about the complex setup of tools and configurations. &lt;/p&gt;

&lt;p&gt;So, now CRA has been deprecated then how to setup pure JSX App? 🤔 &lt;br&gt;
Here I will share Two popular choices(&lt;strong&gt;Vite&lt;/strong&gt; and &lt;strong&gt;Webpack&lt;/strong&gt;) to create a client-based application with the React library. Below Section, We'll compare these tools and give you setup instructions for each. Let’s dive in! 🏊‍♂️&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;em&gt;⚡ Vite vs Webpack 🔧&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Vite&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;-Fast development server with instant hot module replacement (HMR).&lt;br&gt;
-Built-in support for modern JavaScript features.&lt;br&gt;
-Minimal configuration is needed to get started.&lt;/p&gt;

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

&lt;p&gt;-Newer tool, so it may have less community support compared to Webpack.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Webpack&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;-Highly configurable and flexible for complex build setups.&lt;br&gt;
-Extensive plugin ecosystem and community support.&lt;br&gt;
-Proven track record with many large-scale applications.&lt;/p&gt;

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

&lt;p&gt;-Initial configuration can be more complex and time-consuming.&lt;br&gt;
-Slower build times compared to Vite.&lt;br&gt;
-Setting Up a React App with Vite&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Create a New Vite Project:&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;1. Run the Vite command in your terminal&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm create vite@latest my-react-app -- --template react
cd my-react-app
npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Start the Development Server:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Vite Configuration:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Vite requires minimal configuration out of the box. The default setup should work for most React projects.&lt;br&gt;
You can customize the vite.config.js if needed.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Setting Up a React App with Webpack&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;1. Initialize Your Project:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir my-react-app
cd my-react-app
npm init -y
npm install react react-dom
npm install webpack webpack-cli webpack-dev-server html-webpack-plugin babel-loader @babel/core @babel/preset-env @babel/preset-react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Create Project Structure:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; 1. Create a src folder and add index.js and App.js files.
 2. Create a public folder and add an index.html file.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;3. Configure Webpack:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;   Create a webpack.config.js file:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js',
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
        },
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader'],
      },
    ],
  },
  resolve: {
    extensions: ['.js', '.jsx'],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './public/index.html',
    }),
  ],
  devServer: {
    contentBase: path.join(__dirname, 'dist'),
    compress: true,
    port: 9000,
  },
};

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Babel Configuration:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;   Create a .babelrc file:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "presets": ["@babel/preset-env", "@babel/preset-react"]
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Start the Development Server:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx webpack serve&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Both Vite and Webpack offer powerful ways to set up a React application without CRA. Vite provides a faster and simpler setup, ideal for medium projects and rapid development. Webpack, on the other hand, offers extensive configurability and a robust ecosystem, making it suitable for more complex projects.&lt;/p&gt;

&lt;p&gt;Choose the tool that best fits your project requirements and preferences. Happy coding!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webpack</category>
      <category>vite</category>
    </item>
  </channel>
</rss>
