<?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: Damandeep Singh</title>
    <description>The latest articles on Forem by Damandeep Singh (@damandeep_singh_7c4698e97).</description>
    <link>https://forem.com/damandeep_singh_7c4698e97</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%2F3120456%2Ff6156a9d-33fc-4845-bf1c-3a3e0777d292.jpeg</url>
      <title>Forem: Damandeep Singh</title>
      <link>https://forem.com/damandeep_singh_7c4698e97</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/damandeep_singh_7c4698e97"/>
    <language>en</language>
    <item>
      <title>Add a Vertical Player to Your Website</title>
      <dc:creator>Damandeep Singh</dc:creator>
      <pubDate>Sun, 28 Dec 2025 11:46:14 +0000</pubDate>
      <link>https://forem.com/damandeep_singh_7c4698e97/add-a-vertical-player-to-your-website-59b3</link>
      <guid>https://forem.com/damandeep_singh_7c4698e97/add-a-vertical-player-to-your-website-59b3</guid>
      <description>&lt;p&gt;This post describes how to add a vertical player to your website to deliver a smooth, vertically scrollable experience similar to youtube reels and youtube-shorts.&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Farticles%2Fmls8tp0dhacovihfv9no.png" class="article-body-image-wrapper"&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%2Farticles%2Fmls8tp0dhacovihfv9no.png" alt=" " width="800" height="1422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Vertical Player is an immersive, scroll-focused video player built on top of Video.js and powered by Next.js. It’s designed specifically for vertical video playback (think TikTok, Reels, and similar mobile-first experiences), providing a seamless and responsive viewing experience that fits modern vertical content formats.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Utilizes Video.js, a robust open-source HTML5 video player framework that supports extensive customization and plugins. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Offers an interface optimized for vertical scrolling and mobile interaction, making it ideal for apps or sites featuring portrait video feeds. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Is built with Next.js, offering a modern React-based architecture for easy integration and extensibility. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;br&gt; 
&lt;/h2&gt;

&lt;h2&gt;
  
  
  📘 Steps to integrate the player:
&lt;/h2&gt;



&lt;h4&gt;
  
  
  1. Installation:
&lt;/h4&gt;

&lt;p&gt;Intall the npm package (&lt;a href="https://www.npmjs.com/package/vertical-player" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/vertical-player&lt;/a&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 i vertical-player
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Usage:
&lt;/h4&gt;

&lt;p&gt;Attributes: &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Required&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;data&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;object[]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;td&gt;Array of objects containing asset URL and metadata: &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;title&lt;/code&gt;, &lt;code&gt;description&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;handleLike&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;fn()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;Callback function triggered when the &lt;strong&gt;Like&lt;/strong&gt; button is clicked&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;handleShare&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;fn()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;Callback function triggered when the &lt;strong&gt;Share&lt;/strong&gt; button is clicked&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;data[] : Array of objects containing url of the asset and metadata: id, title, description.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;url&lt;/strong&gt;: mp4/hls url of the asset.&lt;br&gt;
 &lt;strong&gt;id&lt;/strong&gt;: unique id for internal handling of the player.&lt;br&gt;
 &lt;strong&gt;title&lt;/strong&gt;: text which is displayed at the bottom of each player.&lt;br&gt;
 &lt;strong&gt;tag&lt;/strong&gt;: category which is displayer at the bottom of each player.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; handleLike(): Callback function which gets fired when like button is clicked on a player.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sample response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "status": true,
    "name": "like",
    "id": 1
}
&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;{
    "status": false,
    "name": "unlike",
    "id": 1
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt; handleShare() : Callback function which gets fired when share button is clicked on a player.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sample response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "name": "share",
    "id": 1
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;⭐️ Check the react component below for complete usage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client"
import {VerticalPlayer} from 'vertical-player/esm/index.es.js';


export default function Home() {
  const handleLike=(e)=&amp;gt;{
    console.log(e); 
  }

  const handleShare=(e)=&amp;gt;{
    console.log(e);
  }

  const DATA: any = [
        {
            id: 1,
            tag: "BRAND",
            asset_url: 'https://www.abc.com/~dnn/clips/RW20seconds_2.mp4',
            description: 'This is a simple description which describes the video'
        },
        {
            id: 2,
            tag: "BRAND",
            asset_url: 'https://www.abc.com/~dnn/clips/RW20seconds_2.mp4',
            description: 'This is a simple description which describes the video'
        },
        {
            id: 3,
            tag: "BRAND",
            asset_url: 'https://www.abc.com/~dnn/clips/RW20seconds_2.mp4',
            description: 'This is a simple description which describes the video'
        },
        {
            id: 4,
            tag: "BRAND",
            asset_url: 'https://www.abc.com/~dnn/clips/RW20seconds_2.mp4',
            description: 'This is a simple description which describes the video'
        },
        {
            id: 5,
            tag: "BRAND",
            asset_url: 'https://www.abc.com/~dnn/clips/RW20seconds_2.mp4',
            description: 'This is a simple description which describes the video'
        },

    ];
  return (
    &amp;lt;VerticalPlayer data={DATA} handleLike={handleLike} handleShare={handleShare}  /&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h4&gt;
  
  
  3. Demo:
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://github.com/user-attachments/assets/44fc682d-dea6-4013-8daf-113058a68cf6" rel="noopener noreferrer"&gt;https://github.com/user-attachments/assets/44fc682d-dea6-4013-8daf-113058a68cf6&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;More information :-&lt;br&gt;
📂 GitHub: &lt;a href="https://github.com/dds05/vertical-player" rel="noopener noreferrer"&gt;https://github.com/dds05/vertical-player&lt;/a&gt;&lt;br&gt;
📦 NPM : &lt;a href="https://www.npmjs.com/package/vertical-player" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/vertical-player&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;br&gt; 
&lt;/h2&gt;

&lt;p&gt;Like this? Don’t forget to leave a ⭐️ on &lt;a href="https://github.com/dds05?tab=repositories" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>videojs</category>
      <category>verticalplayer</category>
      <category>reels</category>
      <category>shorts</category>
    </item>
    <item>
      <title>AWS MediaTailor : Server Side Ad Insertion (SSAI)</title>
      <dc:creator>Damandeep Singh</dc:creator>
      <pubDate>Wed, 17 Sep 2025 18:55:44 +0000</pubDate>
      <link>https://forem.com/damandeep_singh_7c4698e97/aws-mediatailor-server-side-ad-integration-ssai-g3n</link>
      <guid>https://forem.com/damandeep_singh_7c4698e97/aws-mediatailor-server-side-ad-integration-ssai-g3n</guid>
      <description>&lt;h2&gt;
  
  
  What is SSAI?
&lt;/h2&gt;

&lt;p&gt;Server-Side Ad Insertion (SSAI) is a technology where ads are stitched directly into the video stream on the server before it reaches the viewer’s device. With SSAI, the video player receives a single, continuous stream that includes both the main content and the ads, making the transitions between them seamless.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why ?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Seamless playback experience: No buffering or jarring transitions between content and ads.&lt;/li&gt;
&lt;li&gt;Bypasses ad blockers: Since ads are part of the main stream, it’s harder for ad blockers to filter them out.&lt;/li&gt;
&lt;li&gt;Consistent performance across devices: Works smoothly on various platforms and devices without heavy client-side logic.&lt;/li&gt;
&lt;li&gt;Better measurement &amp;amp; analytics: Offers precise tracking through server-side and client-side beaconing.&lt;/li&gt;
&lt;li&gt;Scalability: Easier to manage ad workflows on the server rather than on individual client apps.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This article covers how to integrate MediaTailor SSAI with your video player and covers all the frontend aspects.&lt;/p&gt;

&lt;p&gt;For this, I will be using example of video.js.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A glimpse about video.js&lt;/strong&gt; :-&lt;br&gt;
Video.js is an open source javascript based video player which is used by approx 800,000 websites.&lt;/p&gt;

&lt;p&gt;✨ Bonus: Includes a &lt;a href="https://github.com/dds05/videojs-mediatailor-ssai" rel="noopener noreferrer"&gt;custom plugin&lt;/a&gt; that facilitates ad markers, an ad counter with a countdown timer, and beaconing.&lt;/p&gt;

&lt;p&gt;For more insights into backend integration, check out this &lt;a href="https://medium.com/@s.sukhbirsohal/how-to-do-server-side-ad-insertion-ssai-with-mediatailor-and-your-video-encoder-34902fc0ec53" rel="noopener noreferrer"&gt;article&lt;/a&gt;, which dives deep into the server aspects of SSAI."&lt;/p&gt;



&lt;h2&gt;
  
  
  📘 Steps to Integrate SSAI Workflow
&lt;/h2&gt;

&lt;p&gt;Here are the steps required to set up AWS MediaTailor SSAI with your video player. :-&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;br&gt; 
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Session URL formation :
&lt;/h3&gt;

&lt;p&gt;Now the first thing is &lt;strong&gt;session url&lt;/strong&gt; which is basically the post api call which is initiated from the player to the stitching service (MediaTailor) which passes it further to the ads server (Eg. FreeWheel).&lt;/p&gt;

&lt;p&gt;You typically generate the session URL by replacing certain parts of the manifest URL:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replace &lt;strong&gt;‘/dash/’&lt;/strong&gt;  with &lt;strong&gt;‘/session/’&lt;/strong&gt; for MPD assets (DASH).&lt;/li&gt;
&lt;li&gt;Replace &lt;strong&gt;‘/master/’&lt;/strong&gt;  with &lt;strong&gt;‘/session/’&lt;/strong&gt; for HLS assets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example final session URL:-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://domain.example..com/v1/session/aesdnsjdsk/Renditions_asset/20250805/1754403862031_sample_HD_TVE_SAMPLE_ASSET_07172025_7830k_mp4_CUSTOM_CODEC_TS_DRM_DASH_DRM/dash/stream.mpd" rel="noopener noreferrer"&gt;https://domain.example..com/v1/session/aesdnsjdsk/Renditions_asset/20250805/1754403862031_sample_HD_TVE_SAMPLE_ASSET_07172025_7830k_mp4_CUSTOM_CODEC_TS_DRM_DASH_DRM/dash/stream.mpd&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also check with your backend team on how to create the session link as it can be done differently on the basis of CDN and other mapping. There is also the possibility of not doing this on the player all together and having it done by the server using the video id and then the server is responsible to just send you manifest and tracking url.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;br&gt; 
&lt;/h2&gt;
&lt;h3&gt;
  
  
  2. POST Request to Get Manifest and Tracking URL
&lt;/h3&gt;

&lt;p&gt;Once you have the session url , you now need to send the url as a POST request with the necessary &lt;strong&gt;key:value&lt;/strong&gt; pairs required by Ad decision server.&lt;/p&gt;

&lt;p&gt;Note that user-agent is an essential header which needs to be passed in order to ensure that the ad decision server stitches the ad seamlessly.&lt;/p&gt;

&lt;p&gt;For a web browser, we don’t need to explicitly send as it is managed by the browser.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;br&gt; 
&lt;/h2&gt;
&lt;h3&gt;
  
  
  3. Parsing the Response.
&lt;/h3&gt;

&lt;p&gt;Once you post the session url , you will get the following response :-&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
manifestUrl:"/v1/dash/a2769ff6f508fb0f68aca8782209ab59ae7a5db0/sample/Renditions/20250805/1754403862031_sample_mp4_CUSTOM_CODEC_TS_DRM_DASH_DRM/dash/stream.mpd?aws.sessionId=dz2d6359-4302-4fb2-a3c4-7cefa9468d42",
trackingUrl:"/v1/tracking/a2769ff6f508fb5f68aca8782209ab59ae7a5db0/samoke/eb7d6e59-4302-4fb2-a3c4-7cefa9468d32"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the response, you will get the paths of &lt;strong&gt;tracking url&lt;/strong&gt; and &lt;strong&gt;manifest url&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To construct the full URLs, prepend the same domain you used for the POST request.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tracking URL → Contains ad details and beacons&lt;/li&gt;
&lt;li&gt;Manifest URL → Contains stitched content with ads&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pass the manifestURL in videojs to run the stitched content.&lt;/p&gt;

&lt;p&gt;Example: Play the stitched asset.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;player.src( {src: ‘manifestUrl’ , type :  ‘application/x-mpegURL“} )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once set, the player will seamlessly play content + ads as a single stream.&lt;/p&gt;

&lt;p&gt;This will allow the stitched asset to play seamlessly.&lt;/p&gt;

&lt;p&gt;Now, let's move forward with showing the ad-markers on the seekbar  and managing advertisement beacons.&lt;/p&gt;

&lt;p&gt;Tracking URL is the source of truth for managing anything related to the ads in case of aws media tailor.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;br&gt; 
&lt;/h2&gt;

&lt;h3&gt;
  
  
  4. Working with Tracking URL
&lt;/h3&gt;

&lt;p&gt;Ensure that the updatedManifest URL is loaded into the player before calling the tracking URL.&lt;br&gt;
This is an important step because if you call the tracking URL first without loading the updated manifest url with sessionId, you will end up getting an empty response from the stitching service (aws-mediatailor).&lt;/p&gt;

&lt;p&gt;Once the asset is loaded, you can simply call the tracking url as shown below: &lt;/p&gt;

&lt;p&gt;Eg:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;player.one(‘loadeddata’, async()=&amp;gt;{
    // initiate get request for tracking url.
    getTrackingData();
})

async function getTrackingData(){
    const res =  await fetch(trackingUrl);
    const data = await res.json();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initiate a get request to retrieve all the advertisement related data.&lt;/p&gt;

&lt;p&gt;You will get a JSON based response as a result.&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Farticles%2Fgejhs532ovcv9h21jkio.png" class="article-body-image-wrapper"&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%2Farticles%2Fgejhs532ovcv9h21jkio.png" alt=" " width="800" height="678"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The ‘&lt;strong&gt;avails&lt;/strong&gt;’ key is an array of objects which consists of all the ad pods present in the stitched asset.&lt;/p&gt;

&lt;p&gt;Now here, the response might not include ads in all the pods and you can get an empty array for some cases. &lt;/p&gt;

&lt;p&gt;You can now mark the ad pods on the video.js player's seekbar based on this data.&lt;/p&gt;

&lt;p&gt;Since each ad pod has the ‘&lt;strong&gt;startTimeInSeconds&lt;/strong&gt;‘ key , we can mark that ad pod on the seekbar.&lt;/p&gt;

&lt;p&gt;You can also use this &lt;a href="https://github.com/dds05/videojs-mediatailor-ssai" rel="noopener noreferrer"&gt;plugin&lt;/a&gt; which basically does the job with many other features as well.&lt;/p&gt;

&lt;p&gt;VideoJS Player with Ad Markers and Ad counter :-&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Farticles%2Fsfa1v6aldx22s65mbcef.png" class="article-body-image-wrapper"&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%2Farticles%2Fsfa1v6aldx22s65mbcef.png" alt=" " width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;br&gt; 
&lt;/h2&gt;

&lt;h3&gt;
  
  
  5. Beaconing (Client-Side Tracking)
&lt;/h3&gt;

&lt;p&gt;Now here comes the client side beaconing. &lt;/p&gt;

&lt;p&gt;In AWS MediaTailor, beacons are small tracking signals sent to an ad server to report on viewer ad engagement, indicating milestones like the start or completion of an ad. AWS MediaTailor supports both server-side (where MediaTailor sends the beacons) and client-side (where the player sends the beacons) tracking methods to provide granular metrics for ad performance and impression measurement.&lt;/p&gt;

&lt;p&gt;Lets discuss about the client side beacon handling :-&lt;/p&gt;

&lt;p&gt;The ad pod contains an ‘&lt;strong&gt;ads&lt;/strong&gt;’ key which is an  array of objects.&lt;/p&gt;

&lt;p&gt;Inside each object, we have the ‘&lt;strong&gt;trackingEvents&lt;/strong&gt;’ key which consists of all the beacons related to that particular ad.&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Farticles%2F8itwvy2o7hzw52k0t3kw.jpeg" class="article-body-image-wrapper"&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%2Farticles%2F8itwvy2o7hzw52k0t3kw.jpeg" alt=" " width="800" height="847"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now , each trackingEvent has the ‘&lt;strong&gt;startTimeInSeconds&lt;/strong&gt;’ which denotes when this beacon event should be triggered. It also has the ‘&lt;strong&gt;beaconUrls&lt;/strong&gt;’ key which consists of the url for that beacon.&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Farticles%2Fpdpvlwxuw1bjvej6j0rd.jpeg" class="article-body-image-wrapper"&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%2Farticles%2Fpdpvlwxuw1bjvej6j0rd.jpeg" alt=" " width="800" height="895"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For a particular advertisement, we are supposed to send a get request exactly as per the '&lt;strong&gt;startTimeInSeconds&lt;/strong&gt;'.&lt;/p&gt;

&lt;p&gt;Now, in video.js or any other web based player we can make use of player.on(‘timeupdate’,cb) event in order to facilitate this logic.&lt;/p&gt;

&lt;p&gt;⚠️Caution: Since timeupdate fires 4-5 times/second. It is important to handle the logic carefully.&lt;/p&gt;

&lt;h4&gt;
  
  
  You can also this &lt;a href="https://github.com/dds05/videojs-mediatailor-ssai" rel="noopener noreferrer"&gt;plugin&lt;/a&gt;. It handles the beacon logic as well as it provides other basic features for ssai integration.
&lt;/h4&gt;

&lt;h2&gt;
  
  
  &lt;br&gt;
&lt;/h2&gt;

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

&lt;p&gt;That’s it!&lt;br&gt;
You now have a fully functional AWS MediaTailor SSAI integration with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Session URL creation&lt;/li&gt;
&lt;li&gt;Manifest loading&lt;/li&gt;
&lt;li&gt;Tracking data handling&lt;/li&gt;
&lt;li&gt;Ad markers on the seek bar&lt;/li&gt;
&lt;li&gt;Client-side beacon tracking&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also read the &lt;a href="https://docs.aws.amazon.com/mediatailor/latest/ug/server-guided.html" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt; of AWS Mediatailor for more insights.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>ssai</category>
      <category>advertisement</category>
      <category>videojs</category>
    </item>
    <item>
      <title>Videojs Theme Kit — Effortless Player Control Customization</title>
      <dc:creator>Damandeep Singh</dc:creator>
      <pubDate>Wed, 13 Aug 2025 16:31:34 +0000</pubDate>
      <link>https://forem.com/damandeep_singh_7c4698e97/videojs-theme-kit-effortless-player-control-customization-1e7j</link>
      <guid>https://forem.com/damandeep_singh_7c4698e97/videojs-theme-kit-effortless-player-control-customization-1e7j</guid>
      <description>&lt;h3&gt;
  
  
  About Video.js : &lt;a href="https://videojs.com/" rel="noopener noreferrer"&gt;https://videojs.com/&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;While Video.js comes with a default skin, it offers very limited customization out of the box.&lt;/p&gt;

&lt;p&gt;If you want to change the look by switching to a modern design, adjusting colors to match your brand, or quickly trying out different styles, then you often have to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write custom CSS overrides&lt;/li&gt;
&lt;li&gt;Deal with theme conflicts&lt;/li&gt;
&lt;li&gt;Manually maintain style changes across updates&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Video.js Theme Kit removes all that hassle.&lt;/p&gt;

&lt;p&gt;✨ Key Features :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🎯 4 modern, ready to use themes: Slate, Spaced, Sleek, and Zen.&lt;/li&gt;
&lt;li&gt;🎨 Infinite color customization to perfectly match your brand aesthetics.&lt;/li&gt;
&lt;li&gt;⚡ Simple installation and setup for a smooth developer experience.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;br&gt; 
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How to use it?
&lt;/h3&gt;

&lt;p&gt;It is pretty simple.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; npm install videojs-theme-kit
&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; player.on('ready',()=&amp;gt;{
   player.theme({
     skin: SKIN_NAME,
     color: 'HEXCODE_OF_THE_COLOR'  //optional
   })
 })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;br&gt; 
&lt;/h2&gt;

&lt;h3&gt;
  
  
  More information :-
&lt;/h3&gt;

&lt;p&gt;🔗 Demo: &lt;a href="https://videojs-theme-kit-site.vercel.app/" rel="noopener noreferrer"&gt;https://videojs-theme-kit-site.vercel.app/&lt;/a&gt;&lt;br&gt;
📂 GitHub: &lt;a href="https://github.com/dds05/videojs-theme-kit" rel="noopener noreferrer"&gt;https://github.com/dds05/videojs-theme-kit&lt;/a&gt;&lt;br&gt;
📦 NPM : &lt;a href="https://www.npmjs.com/package/videojs-theme-kit" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/videojs-theme-kit&lt;/a&gt;&lt;br&gt;
ℹ️ About Video.js : &lt;a href="https://videojs.com/" rel="noopener noreferrer"&gt;https://videojs.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>videojs</category>
      <category>playercustomisation</category>
      <category>videojsplugin</category>
    </item>
    <item>
      <title>Is innerHTML Dangerous? Myth vs Reality</title>
      <dc:creator>Damandeep Singh</dc:creator>
      <pubDate>Tue, 01 Jul 2025 13:30:00 +0000</pubDate>
      <link>https://forem.com/damandeep_singh_7c4698e97/is-innerhtml-dangerous-myth-vs-reality-p5i</link>
      <guid>https://forem.com/damandeep_singh_7c4698e97/is-innerhtml-dangerous-myth-vs-reality-p5i</guid>
      <description>&lt;p&gt;&lt;strong&gt;innerHTML&lt;/strong&gt; has been around since the early days of the web.&lt;br&gt;
It’s used in millions of websites to manipulate the DOM efficiently.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;br&gt; 
&lt;/h2&gt;
&lt;h3&gt;
  
  
  ✅ Advantages of innerHTML:-
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simplicity and Convenience&lt;/strong&gt; : It is very easy to use and perfect for quickly injecting or replacing a block of HTML.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Performance&lt;/strong&gt; : Updating large chunks of HTML in one go is often faster than building DOM nodes individually. Especially useful for rendering static templates or HTML responses from the server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Supports Complete HTML Features&lt;/strong&gt; : Capable of rendering: nested elements , inline styles , SVGs etc.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  &lt;br&gt;
&lt;/h2&gt;
&lt;h3&gt;
  
  
  ⛔️ When innerHTML Becomes Dangerous ?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Security Risk (XSS)&lt;/strong&gt; : It can easily lead to Cross-Site Scripting (XSS) vulnerabilities if used with user-controlled data.
It can easily be exploited to inject malicious scripts if you're inserting untrusted content. &lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const userInput = document.getElementById('comment-box').value;
element.innerHTML = userInput;  // If userInput contains &amp;lt;script&amp;gt;alert('XSS')&amp;lt;/script&amp;gt;, it will execute.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;2. &lt;strong&gt;DOM Rebuild Overhead&lt;/strong&gt; : Using innerHTML repeatedly (like in a timer, clock, or live feed) forces the browser to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remove all existing child elements&lt;/li&gt;
&lt;li&gt;Parse the new HTML string&lt;/li&gt;
&lt;li&gt;Rebuild and insert everything again&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This constant process is inefficient for real-time updates. It leads to unnecessary reflows and repaints, which can affect performance.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔒 Recommendation:
&lt;/h3&gt;

&lt;p&gt;✅ Use innerHTML only when you control 100% of the content being inserted.&lt;/p&gt;

&lt;p&gt;✅ If the content comes from a user (like a form or a comment), use textContent to show it as plain text, or sanitize it with a tool like &lt;a href="https://www.npmjs.com/package/dompurify" rel="noopener noreferrer"&gt;DOMPurify&lt;/a&gt; before adding it to the page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Safer option:
const safeHTML = DOMPurify.sanitize(userInput);
element.innerHTML = safeHTML;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;br&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  𐄷 Verdict:-
&lt;/h3&gt;

&lt;p&gt;innerHTML is safe when the content is completely trusted — i.e., not user controlled. It remains a useful part of the web platform due to its &lt;strong&gt;simplicity&lt;/strong&gt;, &lt;strong&gt;performance benefits&lt;/strong&gt;, and legacy support.&lt;/p&gt;

&lt;p&gt;As developers, it’s our responsibility to use it wisely. We should avoid it entirely when working with untrusted or dynamic input, to prevent serious vulnerabilities like &lt;strong&gt;Cross-Site Scripting (XSS)&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Let me know what you think about this.&lt;/p&gt;

</description>
      <category>dom</category>
      <category>javascript</category>
      <category>security</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Best Practices for Using Dynamic SVGs in Your Frontend</title>
      <dc:creator>Damandeep Singh</dc:creator>
      <pubDate>Sun, 29 Jun 2025 18:54:57 +0000</pubDate>
      <link>https://forem.com/damandeep_singh_7c4698e97/best-practices-for-using-dynamic-svgs-in-your-frontend-5hg3</link>
      <guid>https://forem.com/damandeep_singh_7c4698e97/best-practices-for-using-dynamic-svgs-in-your-frontend-5hg3</guid>
      <description>&lt;h2&gt;🔄 How often have you needed to update icons dynamically based on user interaction?&lt;/h2&gt;

&lt;p&gt;Whether it's toggling a button state, switching themes, or updating a UI element, dynamically updating icons is a common need in frontend development. &lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🚫 Naive Approach :-
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const button = document.getElementById('play-toggle');

const onPlay = () =&amp;gt; {
  button.innerHTML = `&amp;lt;!-- SVG markup for play icon --&amp;gt;`;
};

const onPause = () =&amp;gt; {
  button.innerHTML = `&amp;lt;!-- SVG markup for pause icon --&amp;gt;`;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method uses innerHTML to inject SVGs on each toggle. While this works, it has two major drawbacks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security Risk&lt;/strong&gt;: &lt;em&gt;&lt;code&gt;innerHTML&lt;/code&gt;&lt;/em&gt; is prone to XSS (Cross-Site Scripting) attacks and is generally discouraged for dynamic updates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Performance Overhead&lt;/strong&gt;: Even if replaced with &lt;em&gt;&lt;code&gt;appendChild()&lt;/code&gt;&lt;/em&gt; or similar safer methods, this approach re-renders the entire SVG each time, leading to unnecessary DOM updates.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  ✅ Efficient &amp;amp; Safe Approach :-
&lt;/h3&gt;

&lt;p&gt;A cleaner, more efficient, and secure solution is to define your SVGs once using &lt;code&gt;&amp;lt;symbol&amp;gt;&lt;/code&gt; and reference them dynamically using &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt;.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Checkout the code 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;svg xmlns="http://www.w3.org/2000/svg" style="display:none"&amp;gt;
    &amp;lt;defs&amp;gt;
      &amp;lt;symbol id="vjs-icon-play" viewBox="0 0 512 512"&amp;gt;
        &amp;lt;path fill="currentColor" d="M108.9 66.5v353L403 242.1zm25.3 49.1 212.3 126.7-212.3 128z"&amp;gt;&amp;lt;/path&amp;gt;
      &amp;lt;/symbol&amp;gt;
      &amp;lt;symbol id="vjs-icon-pause" viewBox="0 0 512 512"&amp;gt;
        &amp;lt;path fill="currentColor" d="M98.2 422.5h121.6v-359H98.2zm20.4-  338.7h80.8v318.4h-80.8zm173.6-20.3v359h121.6v-359zm101.2 338.7h-80.8V83.8h80.8z"&amp;gt;
        &amp;lt;/path&amp;gt;
      &amp;lt;/symbol&amp;gt;
    &amp;lt;/defs&amp;gt;
&amp;lt;/svg&amp;gt;


&amp;lt;!-- Play/Pause Toggle Button --&amp;gt;
&amp;lt;button id="play-toggle"&amp;gt;
  &amp;lt;svg id="play-toggle-icon" viewBox="0 0 512 512" width="32" height="32"&amp;gt;
    &amp;lt;use href="#vjs-icon-play"&amp;gt;&amp;lt;/use&amp;gt;
  &amp;lt;/svg&amp;gt;
&amp;lt;/button&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;const icon = document.querySelector('#play-toggle-icon use');

const onPlay = () =&amp;gt; {
  icon.setAttribute('href', '#vjs-icon-play');
};

const onPause = () =&amp;gt; {
  icon.setAttribute('href', '#vjs-icon-pause');
};

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  📘 Quick Reference :-
&lt;/h3&gt;

&lt;p&gt;ℹ &lt;code&gt;&amp;lt;defs&amp;gt;&lt;/code&gt; : It is an SVG container used to store elements such as &lt;code&gt;&amp;lt;symbol&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;gradient&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;filter&amp;gt;&lt;/code&gt;, etc., that are not rendered directly in the SVG output. Instead, these definitions can be referenced later by other SVG elements.&lt;/p&gt;

&lt;p&gt;ℹ &lt;code&gt;&amp;lt;symbol&amp;gt;&lt;/code&gt; : It is an SVG element used to define reusable graphic content — such as icons, shapes, or patterns — without rendering it immediately.&lt;/p&gt;

&lt;p&gt;ℹ  &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt; : It is an element in SVG which is designed to reference and reuse other SVG elements—especially things like icons, shapes, or graphic elements—without duplicating code.&lt;/p&gt;






&lt;h3&gt;
  
  
  💡 Why This Approach Is Better?
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Security&lt;/strong&gt;: No innerHTML, hence safer from injection attacks.&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;Performance&lt;/strong&gt;: The SVG is only defined once; only the reference (href) changes on interaction.&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;Maintainability&lt;/strong&gt;: Centralised icon definitions make it easy to manage and scale.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Let me know what do you think about this? &lt;br&gt;&lt;/p&gt;

</description>
      <category>rendering</category>
      <category>optimisation</category>
      <category>javascript</category>
      <category>svg</category>
    </item>
    <item>
      <title>👨‍💻 What is Request Coalescing?</title>
      <dc:creator>Damandeep Singh</dc:creator>
      <pubDate>Thu, 26 Jun 2025 18:42:34 +0000</pubDate>
      <link>https://forem.com/damandeep_singh_7c4698e97/what-is-request-coalescing-15fc</link>
      <guid>https://forem.com/damandeep_singh_7c4698e97/what-is-request-coalescing-15fc</guid>
      <description>&lt;p&gt;Recently, I encountered a scenario where multiple API requests were being made from a common function triggered by various initiators. To address this, I discovered the concept of request coalescing.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Request coalescing is a technique for tracking ongoing API requests and sharing the result among all simultaneous requests.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h4&gt;
  
  
  Why is it important in frontend development?
&lt;/h4&gt;

&lt;p&gt;In applications that rely on authentication tokens, it's common for multiple parts of the app to trigger requests around the same time. If the token has expired, these requests might all attempt a token refresh simultaneously.&lt;/p&gt;

&lt;p&gt;Request coalescing ensures that only one refresh request is actually made. All subsequent requests receive the result of that shared ongoing promise, avoiding redundant network calls and improving performance.&lt;/p&gt;

&lt;p&gt;Check out the code snippet below :-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let refreshTokenPromise = null;

// function to get auth token
const getAuthorizationToken = async () =&amp;gt; {
  let token = Cookies.get("token") &amp;amp;&amp;amp; JSON.parse(Cookies.get("token"));

  // if token is expired
  if (token &amp;amp;&amp;amp; isTokenExpired(token)) {
    if (!refreshTokenPromise) {
      // Initiate a new refresh token request
      refreshTokenPromise = fetchRefreshToken()
        .then((result) =&amp;gt; {
          const authToken = result?.authorizationToken;
          const refreshToken = result?.refreshToken;

          if (authToken) {
            Cookies.set("token", authToken);
          }
          if (refreshToken) {
            refreshTokenManager().set(refreshToken);
          }
          return authToken || token;
        })
        .catch((e) =&amp;gt; {
          console.error("Error fetching refresh token", e);
          return token;
        })
        .finally(() =&amp;gt; {
          // Reset the pending request tracker regardless of success or failure
          refreshTokenPromise = null;
        });
    }
    // Return the promise of the ongoing refresh request
    return refreshTokenPromise;
  } else {
    return token;
  }
};

const isTokenExpired = (token) =&amp;gt; {
  let currentTime = new Date().getTime();
  if (token.expiryTime &amp;lt; currentTime) return true;
};

const fetchRefreshToken = async () =&amp;gt; {
  // api call to fetch refresh token and return the response
};

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

&lt;/div&gt;



&lt;p&gt;So, if you look at the code above, you’ll notice that we’re caching the ongoing promise of the API request. This means that if the function is triggered multiple times simultaneously, it won’t initiate multiple requests—instead, it will return the same in-progress promise to all callers.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Checkout the flow diagram for more clear understanding :-
&lt;/h4&gt;

&lt;p&gt;&lt;a href="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%2Farticles%2F46lgaq9u3le5ydqvwoan.png" class="article-body-image-wrapper"&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%2Farticles%2F46lgaq9u3le5ydqvwoan.png" alt=" " width="800" height="583"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;This effectively ensures that only &lt;strong&gt;one API call&lt;/strong&gt; is made, and the result is &lt;strong&gt;shared across all request initiators&lt;/strong&gt;. Once the promise resolves, all the awaiting calls receive the same response, reducing redundant network requests and improving overall efficiency.&lt;/p&gt;



&lt;p&gt;Let me know what you think in the comments !&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>api</category>
      <category>authentication</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Singleton with IIFE for state management in JavaScript</title>
      <dc:creator>Damandeep Singh</dc:creator>
      <pubDate>Mon, 23 Jun 2025 19:46:19 +0000</pubDate>
      <link>https://forem.com/damandeep_singh_7c4698e97/singleton-with-iife-for-state-management-in-javascript-5cnl</link>
      <guid>https://forem.com/damandeep_singh_7c4698e97/singleton-with-iife-for-state-management-in-javascript-5cnl</guid>
      <description>&lt;h3&gt;
  
  
  Ever needed a centralized configuration manager in your JavaScript app? 🤔 &lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;In modern JavaScript apps, managing shared state or configuration often means reaching for heavy tools like Redux, Zustand, or context APIs. But what if you're working on a &lt;strong&gt;small utility&lt;/strong&gt;, a &lt;strong&gt;framework-agnostic widget&lt;/strong&gt;, or just need a &lt;strong&gt;simple global config&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;This is where the Singleton pattern with an IIFE (Immediately Invoked Function Expression) comes in handy.&lt;/p&gt;

&lt;p&gt;It offers a &lt;strong&gt;lightweight&lt;/strong&gt;, &lt;strong&gt;zero-dependency&lt;/strong&gt; way to encapsulate state, avoid global pollution, and keep things clean—all without introducing a full-blown state manager. &lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🔧 Here's how I use the Singleton + IIFE pattern:&lt;br&gt;&lt;br&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const configManager = (() =&amp;gt; {
  let config = {};

  return {
    set(key, value) {
      config[key] = value;
    },
    get(key) {
      return key ? config[key] : config;
    }
  };
})();

// Usage
configManager.set("theme", "dark");
configManager.set("language", "en");

console.log(configManager.get("theme"));   // "dark"
console.log(configManager.get());          
// { theme: "dark", language: "en" }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🛠️ Practical Uses of Singleton IIFE :- &lt;br&gt;&lt;br&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1️⃣ Small Projects or Utilities
&lt;/h4&gt;

&lt;p&gt;When you're building a small app or a quick utility, full-blown state management is often unnecessary.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lightweight, zero-dependency
&lt;/li&gt;
&lt;li&gt;Simple centralized storage for shared data or config
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2️⃣ Global Configuration / Settings
&lt;/h4&gt;

&lt;p&gt;Perfect for app-wide settings that don’t require reactivity:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🌐 &lt;code&gt;API_BASE_URL&lt;/code&gt;, &lt;code&gt;locale&lt;/code&gt;, &lt;code&gt;featureToggles&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;🎨 Theme settings: &lt;code&gt;dark&lt;/code&gt;, &lt;code&gt;light&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;🌍 Language preferences: &lt;code&gt;en&lt;/code&gt;, &lt;code&gt;fr&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just a simple, centralized store to &lt;strong&gt;read/write&lt;/strong&gt; values—no state management library needed.&lt;/p&gt;

&lt;h4&gt;
  
  
  3️⃣ Vanilla JS or Non-Framework Environments
&lt;/h4&gt;

&lt;p&gt;If you're working outside of modern UI frameworks like React or Vue (e.g., in a widget or a JavaScript library), this approach works great.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No React/Redux overhead
&lt;/li&gt;
&lt;li&gt;Keeps your footprint minimal and portable
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4️⃣ Encapsulation + Immutability
&lt;/h4&gt;

&lt;p&gt;Using a Singleton with an IIFE gives you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🔒 &lt;strong&gt;Private internal state&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;🧪 Access only via controlled &lt;code&gt;get&lt;/code&gt;/&lt;code&gt;set&lt;/code&gt; methods
&lt;/li&gt;
&lt;li&gt;🚫 Prevents accidental mutations
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is especially useful when you want to enforce strict, controlled state updates.&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;If you found this helpful, consider dropping a ❤️ or sharing with a fellow dev!&lt;/p&gt;

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