<?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: Murtaza Nathani</title>
    <description>The latest articles on DEV Community by Murtaza Nathani (@mnathani).</description>
    <link>https://dev.to/mnathani</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%2F72394%2Fc9117f05-e06d-428e-87d3-b97cf157d619.jpeg</url>
      <title>DEV Community: Murtaza Nathani</title>
      <link>https://dev.to/mnathani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mnathani"/>
    <language>en</language>
    <item>
      <title>How the TypeScript Record Type Works</title>
      <dc:creator>Murtaza Nathani</dc:creator>
      <pubDate>Sun, 29 Jan 2023 22:38:38 +0000</pubDate>
      <link>https://dev.to/mnathani/how-the-typescript-record-type-works-4c8</link>
      <guid>https://dev.to/mnathani/how-the-typescript-record-type-works-4c8</guid>
      <description>&lt;p&gt;The &lt;code&gt;Record&lt;/code&gt; type in TypeScript is used to create a dictionary of key-value pairs, where the keys and values can have specific types. A &lt;code&gt;Record&lt;/code&gt; type is essentially an object type, but it provides a way to specify the types of the keys and values for better type checking and code readability.&lt;/p&gt;

&lt;p&gt;The basic syntax for creating a &lt;code&gt;Record&lt;/code&gt; type is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myRecord&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;KeyType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ValueType&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where &lt;code&gt;KeyType&lt;/code&gt; and &lt;code&gt;ValueType&lt;/code&gt; are the types of the keys and values, respectively.&lt;/p&gt;

&lt;p&gt;For example, consider a scenario where you want to create an object that represents a score board in a game of rock-paper-scissors. You can define a Record type with the keys being the possible moves (e.g. "A X" for opponent's move being Rock and user's move being Scissors) and the values being the scores for each combination of moves.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scoreBoard&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A X&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A Y&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A Z&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;B X&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;B Y&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;B Z&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;C X&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;C Y&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;C Z&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&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;A X&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A Y&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A Z&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;B X&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;B Y&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;B Z&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;C X&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;C Y&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;C Z&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;6&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;In this example, the keys of the scoreBoard object are of the type &lt;strong&gt;&lt;code&gt;"A X" | "A Y" | "A Z" | "B X" | "B Y" | "B Z" | "C X" | "C Y" | "C Z"&lt;/code&gt;&lt;/strong&gt;, which represents the possible combinations of moves in the game. The values of the object are of the type &lt;code&gt;number&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;With the &lt;code&gt;Record&lt;/code&gt; type, you can enforce that only valid combinations of moves are used as keys in the object. If you try to access a key that doesn't exist in the object, you'll get a type error, helping you catch errors early in the development process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;scoreBoard&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A Z&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// score is of type number&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;invalidScore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;scoreBoard&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;D X&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// Type 'undefined' is not assignable to type 'number'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, the &lt;code&gt;Record&lt;/code&gt; type provides better code completion and documentation in your &lt;code&gt;IDE&lt;/code&gt;, making it easier to understand the expected keys and values in your &lt;code&gt;objects&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can also use a &lt;code&gt;Record&lt;/code&gt; as a type for a function's parameter or return type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// do something with data&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;data&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;Another use case for &lt;code&gt;Record&lt;/code&gt; is when you want to create an object with a fixed set of keys and specific types for the values. This can be useful when working with configuration objects or data that should only have a specific set of keys and values.&lt;/p&gt;

&lt;p&gt;Using the &lt;code&gt;Record&lt;/code&gt; type in your code provides several benefits, including:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Improved code readability: The &lt;code&gt;Record&lt;/code&gt; type makes it clear what types of keys and values are expected in the object, making it easier for other developers to understand your code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Better type checking: TypeScript will catch errors if you try to assign a value of the wrong type to a key in the object.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Consistency:&lt;br&gt;
The Record type enforces consistency by ensuring that all keys and values in the object have the same types, reducing the likelihood of bugs caused by inconsistent data.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In conclusion, the &lt;code&gt;Record&lt;/code&gt; type in TypeScript is a powerful tool for defining objects with specific types for keys and values. By using the &lt;code&gt;Record&lt;/code&gt; type, you can write more readable, type-safe code that is less prone to bugs caused by inconsistent data.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>career</category>
    </item>
    <item>
      <title>Optimizing to find the top 3 numbers from an array</title>
      <dc:creator>Murtaza Nathani</dc:creator>
      <pubDate>Tue, 24 Jan 2023 15:00:24 +0000</pubDate>
      <link>https://dev.to/mnathani/optimizing-to-find-the-top-3-numbers-from-an-array-15gn</link>
      <guid>https://dev.to/mnathani/optimizing-to-find-the-top-3-numbers-from-an-array-15gn</guid>
      <description>&lt;p&gt;How to find the the top 3 largest number in an array parsing from a file..&lt;/p&gt;

&lt;p&gt;There were many solution popping...  like sorting and grabbing the top 3 elements,&lt;br&gt;
That would require:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;parsing the file to an array --&amp;gt; &lt;code&gt;O(n)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;sorting the array --&amp;gt; &lt;code&gt;O(n)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;getting top --&amp;gt; &lt;code&gt;c&lt;/code&gt; (constant time)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Doing this was boiling my blood.. and i was at unrest, so i wanted to optimize it by:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;parse the file and keep record of top 3 in an array &lt;code&gt;[0, 0, 0]&lt;/code&gt; and keep comparing the current with top 3 to update them.  --&amp;gt; &lt;code&gt;O(n)&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;     &lt;span class="c1"&gt;// current is greater then topThree first then set the all top three  &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;current&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;topThree&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;topThree&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;topThree&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="nx"&gt;topThree&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;topThree&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="nx"&gt;topThree&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

     &lt;span class="c1"&gt;// current is greater then topThree second then set bottom two  &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;current&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;topThree&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;topThree&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;topThree&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;topThree&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="nx"&gt;topThree&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

     &lt;span class="c1"&gt;// current is greater then topThree third then set the third only.  &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;current&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;topThree&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;topThree&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;topThree&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;current&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;For more details check the code for &lt;strong&gt;day 1, aoc 2022&lt;/strong&gt; here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/m-nathani/aoc-2022/blob/main/src/days/day-1.ts" rel="noopener noreferrer"&gt;https://github.com/m-nathani/aoc-2022/blob/main/src/days/day-1.ts&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Looking forward to hear from you on comments to find other learnings you had for day1 or could improve the current approach more. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>cloud</category>
      <category>azure</category>
    </item>
    <item>
      <title>Things learned from AdventOfCode 2022</title>
      <dc:creator>Murtaza Nathani</dc:creator>
      <pubDate>Tue, 24 Jan 2023 15:00:11 +0000</pubDate>
      <link>https://dev.to/mnathani/things-learned-from-adventofcode-2022-54o3</link>
      <guid>https://dev.to/mnathani/things-learned-from-adventofcode-2022-54o3</guid>
      <description>&lt;h3&gt;
  
  
  What is AdventofCode (aoc) ?
&lt;/h3&gt;

&lt;p&gt;Its series of 25 leetcode / problem solving question that you can solve to learn and enjoy.&lt;/p&gt;

&lt;p&gt;Its writtern by &lt;a href="http://was.tl/"&gt;Eric Wastl&lt;/a&gt;, please follow and support his work.&lt;/p&gt;

&lt;p&gt;For more insights check the link below:&lt;br&gt;
&lt;a href="https://adventofcode.com/2022/about"&gt;https://adventofcode.com/2022/about&lt;/a&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Lets Jump to learnings ! :D
&lt;/h3&gt;

&lt;p&gt;Adventofcode has total 25 question, from which to the date of writing i am attempted few out of it.&lt;/p&gt;

&lt;p&gt;Can check the implementation here: &lt;a href="https://github.com/m-nathani/aoc-2022/"&gt;https://github.com/m-nathani/aoc-2022/&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dev.to/mnathani/optimizing-to-find-the-top-3-numbers-from-an-array-15gn"&gt;Day 1&lt;/a&gt; : &lt;a href="https://github.com/m-nathani/aoc-2022/blob/main/src/days/day-1.ts"&gt;code&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dev.to/mnathani/how-the-typescript-record-type-works-4c8"&gt;Day 2&lt;/a&gt; : &lt;a href="https://github.com/m-nathani/aoc-2022/blob/main/src/days/day-2.ts"&gt;code&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Moreover, have learned / revised things i could not have done with the regular programming i do at work &lt;/p&gt;




&lt;p&gt;I was motivated on attempting the aoc last year in 2022 by my colleague &lt;a class="mentioned-user" href="https://dev.to/hendriklammers"&gt;@hendriklammers&lt;/a&gt;, who i admire of how he is keen to learn different techs and solving problems. So thank you. :)&lt;/p&gt;

&lt;p&gt;Regards.&lt;/p&gt;

</description>
      <category>adventofcode</category>
      <category>typescript</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>Are you dealing with IMPOSTER SYNDROME ?</title>
      <dc:creator>Murtaza Nathani</dc:creator>
      <pubDate>Fri, 02 Dec 2022 21:11:52 +0000</pubDate>
      <link>https://dev.to/mnathani/welcome-to-imposter-syndrome-d-3edl</link>
      <guid>https://dev.to/mnathani/welcome-to-imposter-syndrome-d-3edl</guid>
      <description>&lt;h3&gt;
  
  
  Purpose of this article:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What is imposter syndrome ? and You are not alone in this syndrome&lt;/li&gt;
&lt;li&gt;Chance to start sharing with others and thinking about how imposter syndrome is wrapped up in your own life.&lt;/li&gt;
&lt;li&gt;How to handle the syndrome and reduce the effects of it!&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Introducing the syndrome 🥺 &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YLoD1lWC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uqn3u4qfkihi87dmx94x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YLoD1lWC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uqn3u4qfkihi87dmx94x.png" alt="Image imposture syndrome" width="640" height="480"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  “I’m a fraud”
&lt;/h3&gt;

&lt;p&gt;Imposter syndrome is loosely defined as doubting your abilities and feeling like a fraud. It disproportionately affects high-achieving people, who find it difficult to accept their accomplishments.&lt;/p&gt;

&lt;p&gt;Albert Einstein&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The exaggerated esteem in which my lifework is held makes me very ill at ease. I feel compelled to think of myself as an involuntary swindler. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_ZUimZt5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m8bzazr0nll8hj5l2lz3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_ZUimZt5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m8bzazr0nll8hj5l2lz3.png" alt="Image I’m a fraud" width="320" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Kate Winslet&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Sometimes I wake up in the morning before going off to a shoot, and I think, I can’t do this. I’m a fraud.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K1YECiuu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4qmhiegcvls5o58jansl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K1YECiuu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4qmhiegcvls5o58jansl.png" alt="Image Kate Winslet" width="638" height="351"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  “They’re going to find me out”
&lt;/h3&gt;

&lt;p&gt;Most of us have experienced feelings of doubt and unworthiness at some point in our lives. But when your accomplishments are a result of your own knowledge, hard work, and preparation and you still feel inadequate ... you're probably suffering from impostor syndrome.&lt;/p&gt;

&lt;p&gt;Maya Angelou&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I have written 11 books but each time I think ‘Uh-oh, they’re going to find out now. I’ve run a game on everybody, and they’re going to find me out.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v3eVrnnG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/agjimhgsteth2y5xgdlb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v3eVrnnG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/agjimhgsteth2y5xgdlb.png" alt="Image Maya Angelou" width="305" height="326"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  “Everybody else knows more than me”
&lt;/h3&gt;

&lt;p&gt;It's the feeling that everyone else knows exactly what they're doing, but you feel lost. &lt;/p&gt;

&lt;p&gt;Margaret Chan, Director-General, World Health Organisation 2006&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There are an awful lot of people out there who think I’m an expert. How do these people believe all this about me? I’m so much aware of all the things I don’t know.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--utorFEGT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pv6sbf55kf2uo6llmoiy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--utorFEGT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pv6sbf55kf2uo6llmoiy.png" alt="Image Margaret Chan, Director-General, World Health Organisation 2006" width="225" height="225"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  “I’m about to embarrass myself”
&lt;/h3&gt;

&lt;p&gt;Sandberg, Chief Operating Officer, Facebook 2021&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Every time I was called on in class, I was sure that I was about to embarrass myself. Every time I took a test, I was sure that it had gone badly. And every time I didn’t embarrass myself — or even excelled — I believed that I had fooled everyone yet again. One day soon, the jig would be up&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v9uEaadu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3jahcorfzhgs4jf5xxus.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v9uEaadu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3jahcorfzhgs4jf5xxus.png" alt="Image Sandberg, Chief Operating Officer, Facebook" width="275" height="183"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;This is imposter syndrome&lt;/strong&gt; 🚨&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s93XQYtZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/te92a0m3nhd42prxun0g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s93XQYtZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/te92a0m3nhd42prxun0g.png" alt="Image This is imposter syndrome" width="768" height="768"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Imposter syndrome and you &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Let's openly talk about it, and share that you are not alone with this feeling, your comment will help others feel better and come out of imposter syndrome.&lt;/p&gt;

&lt;h3&gt;
  
  
  Poll please 🗳️
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Do you experience imposter syndrome?
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Yes&lt;/li&gt;
&lt;li&gt;Sometimes&lt;/li&gt;
&lt;li&gt;No&lt;/li&gt;
&lt;li&gt;Don’t know enough about imposter syndrome to say&lt;/li&gt;
&lt;li&gt;Other&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Does it affect your professional life? 💼
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;A lot&lt;/li&gt;
&lt;li&gt;A bit&lt;/li&gt;
&lt;li&gt;No&lt;/li&gt;
&lt;li&gt;Don’t know&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Looking forward to hear from you in the comments 📝&lt;/p&gt;




&lt;h2&gt;
  
  
  Lets overcome this shit 💪 &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Share your feeling, talk about it, it's the first step towards overcoming the syndrome.&lt;/li&gt;
&lt;li&gt;Recognize the skills you have already.&lt;/li&gt;
&lt;li&gt;Identify your fears and doubts and make a plan to work on them&lt;/li&gt;
&lt;li&gt;Create a career timeline that works for you and keep track of your accomplishments&lt;/li&gt;
&lt;li&gt;Onboarding is designed to take time. So don't worry if you have joined a new company and it's taking time to adjust.&lt;/li&gt;
&lt;li&gt;Check in with your peers or manager&lt;/li&gt;
&lt;li&gt;Compare with your past self&lt;/li&gt;
&lt;li&gt;Find your place on the Dunning-Kruger curve.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q_G62ZeO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yuprrs9n9kt30aqb6lo1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q_G62ZeO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yuprrs9n9kt30aqb6lo1.png" alt="Image Dunning-Kruger curve" width="640" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The purpose of Dunning-Kruger curve is to understand people's inability to recognize their lack of experience. Because a lack of knowledge leads to not knowing what are you talking about and confidence makes it impossible to realize it. The graphic shows ability curve, overconfidence and competency.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  It never ends:
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;handle imposter syndrome as you progress ! 🎉&lt;/p&gt;
&lt;/blockquote&gt;


&lt;div class="ltag__user ltag__user__id__72394"&gt;
    &lt;a href="/mnathani" class="ltag__user__link profile-image-link"&gt;
      &lt;div class="ltag__user__pic"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PBrFdXYT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--FV4Pq-U4--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/72394/c9117f05-e06d-428e-87d3-b97cf157d619.jpeg" alt="mnathani image"&gt;
      &lt;/div&gt;
    &lt;/a&gt;
  &lt;div class="ltag__user__content"&gt;
    &lt;h2&gt;
&lt;a class="ltag__user__link" href="/mnathani"&gt;Murtaza Nathani&lt;/a&gt;Follow
&lt;/h2&gt;
    &lt;div class="ltag__user__summary"&gt;
      &lt;a class="ltag__user__link" href="/mnathani"&gt;Passionate to share what i learn. I feel it's my responsibility as the community has given many help for developing my career ! &lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


</description>
      <category>discuss</category>
      <category>career</category>
      <category>community</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Delete all node_modules folders from your system ? 🤔</title>
      <dc:creator>Murtaza Nathani</dc:creator>
      <pubDate>Fri, 02 Dec 2022 20:52:00 +0000</pubDate>
      <link>https://dev.to/mnathani/delete-all-nodemodules-folders-from-your-system--4805</link>
      <guid>https://dev.to/mnathani/delete-all-nodemodules-folders-from-your-system--4805</guid>
      <description>&lt;p&gt;&lt;a href="https://media.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%2Fwdzf0a5xo5r0qula61rx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fwdzf0a5xo5r0qula61rx.png" alt="Image meme for how big a node_modules can be"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Is it giving you hard time to remove &lt;code&gt;node_modules&lt;/code&gt; folders from each of your project ? 🙈&lt;/p&gt;

&lt;p&gt;Or&lt;/p&gt;

&lt;p&gt;You never delete &lt;code&gt;node_modules&lt;/code&gt; after finishing project due to the tedious work nature ? 🙊&lt;/p&gt;

&lt;p&gt;Or&lt;/p&gt;

&lt;p&gt;Maybe you forget to delete it most of the time ? 🙉&lt;/p&gt;




&lt;h2&gt;
  
  
  NO WORRIES!!! 🎉
&lt;/h2&gt;

&lt;p&gt;We have one simple command to delete &lt;code&gt;node_modules&lt;/code&gt; folders inside a particular folder... or to delete all &lt;code&gt;node_modules&lt;/code&gt; from the system then run from home directory 🔥&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx npkill
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.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%2Fi71od15daoa0g0so2x1y.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fi71od15daoa0g0so2x1y.gif" alt="Image how npkill works"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Boom! 💥, that's it.. run this command and it shows a &lt;strong&gt;list&lt;/strong&gt; of the &lt;code&gt;node_modules&lt;/code&gt; directories in your system, as well as the size they take up. Then you can select using &lt;em&gt;arrow keys&lt;/em&gt; and &lt;em&gt;spacebar&lt;/em&gt;  to erase it &lt;strong&gt;fast&lt;/strong&gt;, Yay!&lt;/p&gt;
&lt;/blockquote&gt;



&lt;p&gt;For more details check ➡️ &lt;a href="https://www.npmjs.com/package/npkill" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/mnathani" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F72394%2Fc9117f05-e06d-428e-87d3-b97cf157d619.jpeg" alt="mnathani"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mnathani/two-lines-of-css-that-boosts-7x-rendering-performance-4mjd" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Two lines of CSS that boosts 7x rendering performance!&lt;/h2&gt;
      &lt;h3&gt;Murtaza Nathani ・ May 29 '22&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#css&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#performance&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#html&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



</description>
      <category>node</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Best way to learn Closure in JavaScript ?</title>
      <dc:creator>Murtaza Nathani</dc:creator>
      <pubDate>Wed, 22 Jun 2022 19:14:11 +0000</pubDate>
      <link>https://dev.to/mnathani/best-way-to-learn-closure-in-javascript--29dp</link>
      <guid>https://dev.to/mnathani/best-way-to-learn-closure-in-javascript--29dp</guid>
      <description>&lt;p&gt;There are tons of resources out on the web which explain what closure is...&lt;/p&gt;

&lt;p&gt;I will cut the crap of giving this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;a function inside a function bla bla... is closure.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Instead what I will do is to give you a &lt;code&gt;1 minute&lt;/code&gt; snippet that you need to &lt;strong&gt;scan&lt;/strong&gt; and &lt;strong&gt;understand&lt;/strong&gt; the output of the below 👇 code will be (without running on compiler or looking into the answer).&lt;/p&gt;

&lt;p&gt;Once done we can check the answer and learn the concept of it.&lt;br&gt;
Please feel free to comment, would love to respond and learn together.&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;let&lt;/span&gt; &lt;span class="nx"&gt;cachedFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&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="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;cachedFunc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// creates a function that closes over `message`&lt;/span&gt;
    &lt;span class="c1"&gt;// keep in mind `message` inside `log` is different&lt;/span&gt;
    &lt;span class="c1"&gt;// on each call&lt;/span&gt;
    &lt;span class="nx"&gt;cachedFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;cachedFunc&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;goodbye&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;h4&gt;
  
  
  Check the answer below compare:
&lt;/h4&gt;

&lt;p&gt;
  Click to expand the Answer
  &lt;h3&gt;
  
  
  Step by step execution:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;cachedFunc&lt;/code&gt; is declared with &lt;code&gt;null&lt;/code&gt;, and a function &lt;code&gt;log&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On calling &lt;code&gt;log("hello")&lt;/code&gt;, the context of calling &lt;code&gt;log&lt;/code&gt; function is same as the &lt;code&gt;cachedFunc&lt;/code&gt; declared, so it will find it's value to &lt;code&gt;null&lt;/code&gt; as declared in outer scope.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inside the &lt;code&gt;if condition&lt;/code&gt; it will update the &lt;code&gt;cachedFunc&lt;/code&gt; to a inline function which prints argument &lt;code&gt;message&lt;/code&gt; to console.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then it calls &lt;code&gt;cachedFunc&lt;/code&gt; method which results in the message "hello".&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;On the second call &lt;code&gt;log("goodbye")&lt;/code&gt; will not initialize the method again.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;So it will call the method that was in previous scope, in which the value of &lt;code&gt;message&lt;/code&gt; is "hello" and that's why it will print the same "hello" again.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ol&gt;


&lt;h3&gt;
  
  
  Further explanation related to &lt;code&gt;Reactjs&lt;/code&gt;:
&lt;/h3&gt;

&lt;p&gt;Under the hood, &lt;code&gt;useCallback&lt;/code&gt; works in a very similar way. On the first render, React saves the function you pass to &lt;code&gt;useCallback&lt;/code&gt; somewhere and will always return that function.&lt;/p&gt;

&lt;p&gt;Every other render will have your saved function, and will "remember" the scope it was created in, including the old value.&lt;/p&gt;

&lt;p&gt;Without &lt;code&gt;useCallback&lt;/code&gt; or adding dependencies to it, a new function would be created on each render or change in the dependencies, which means it would be able to refer to new with an up-to-date value.&lt;br&gt;
&lt;/p&gt;

&lt;br&gt;
&lt;/p&gt;




&lt;p&gt;Here is the link to &lt;a href="https://codepen.io/m-nathani/pen/YzeoyZZ?editors=1112" rel="noopener noreferrer"&gt;codepen&lt;/a&gt; to further play with it :)&lt;/p&gt;

&lt;p&gt;Regards.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/mnathani" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F72394%2Fc9117f05-e06d-428e-87d3-b97cf157d619.jpeg" alt="mnathani"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mnathani/how-to-cache-bust-frontend-app-132l" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;How to Cache bust web app&lt;/h2&gt;
      &lt;h3&gt;Murtaza Nathani ・ Jun 5 '22&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#react&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#devops&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>JavaScript's unsafe optional chaining is crazy |:</title>
      <dc:creator>Murtaza Nathani</dc:creator>
      <pubDate>Wed, 15 Jun 2022 08:58:18 +0000</pubDate>
      <link>https://dev.to/mnathani/no-unsafe-optional-chaining-is-crazy--4icm</link>
      <guid>https://dev.to/mnathani/no-unsafe-optional-chaining-is-crazy--4icm</guid>
      <description>&lt;h3&gt;
  
  
  Optional chaining:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining" rel="noopener noreferrer"&gt;Optional chaining&lt;/a&gt;  has made life of &lt;code&gt;javaScript&lt;/code&gt; programmer easy by handling the checks using the syntax &lt;code&gt;?.&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;However, here we are &lt;strong&gt;NOT&lt;/strong&gt; to discuss how awesome it is, rather solving a issue how of to safely use it.&lt;/p&gt;




&lt;h3&gt;
  
  
  no-unsafe-optional-chaining
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://eslint.org/docs/rules/no-unsafe-optional-chaining" rel="noopener noreferrer"&gt;no-unsafe-optional-chaining&lt;/a&gt; is an amazing &lt;code&gt;eslint&lt;/code&gt; rule, which help us identify what are we doing wrong with &lt;strong&gt;optional chaining&lt;/strong&gt; and disallows use of optional chaining in contexts where the &lt;code&gt;undefined&lt;/code&gt; value is not allowed.&lt;/p&gt;

&lt;p&gt;I have one case where I need to perform a &lt;code&gt;sort&lt;/code&gt; operation on &lt;code&gt;id&lt;/code&gt; which could be in &lt;code&gt;string&lt;/code&gt; type which make sense to &lt;strong&gt;throw error&lt;/strong&gt; because it could result in &lt;code&gt;NaN&lt;/code&gt;, if &lt;code&gt;order&lt;/code&gt; is not a number as follows:&lt;/p&gt;




&lt;h3&gt;
  
  
  The issue
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sortComparer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;h3&gt;
  
  
  My solution
&lt;/h3&gt;

&lt;p&gt;However, if i do handle &lt;code&gt;no-unsafe-optional-chaining&lt;/code&gt; as follow it still &lt;strong&gt;throws error&lt;/strong&gt; and does not work:&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;const&lt;/span&gt; &lt;span class="nx"&gt;sortComparer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;order&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="o"&gt;-&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;order&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  The way it worked
&lt;/h3&gt;

&lt;p&gt;The only way to make it work is like this:&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;const&lt;/span&gt; &lt;span class="nx"&gt;sortComparer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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;a&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Question ? :S
&lt;/h2&gt;

&lt;p&gt;Does anyone know how to fix this in a better way to avoid this issue ?&lt;/p&gt;

&lt;p&gt;Regards.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/mnathani" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F72394%2Fc9117f05-e06d-428e-87d3-b97cf157d619.jpeg" alt="mnathani"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mnathani/welcome-to-imposter-syndrome-d-3edl" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Are you dealing with IMPOSTER SYNDROME ?&lt;/h2&gt;
      &lt;h3&gt;Murtaza Nathani ・ Dec 2 '22&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#discuss&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#career&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#community&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#productivity&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>lint</category>
      <category>webdev</category>
      <category>discuss</category>
    </item>
    <item>
      <title>How to Cache bust web app</title>
      <dc:creator>Murtaza Nathani</dc:creator>
      <pubDate>Sun, 05 Jun 2022 18:13:20 +0000</pubDate>
      <link>https://dev.to/mnathani/how-to-cache-bust-frontend-app-132l</link>
      <guid>https://dev.to/mnathani/how-to-cache-bust-frontend-app-132l</guid>
      <description>&lt;h2&gt;
  
  
  Why do we need to do cache busting ?
&lt;/h2&gt;

&lt;p&gt;Static file gets cached and can be stored for a long period of time before it ends up expiring. So in order to get the latest &lt;em&gt;features&lt;/em&gt; and &lt;em&gt;fixes&lt;/em&gt; we need to remove the cache so that browsers can get the latest updates.&lt;/p&gt;

&lt;p&gt;Additionally, have you ever felt &lt;strong&gt;web application&lt;/strong&gt; like &lt;code&gt;soundcloud&lt;/code&gt;, &lt;code&gt;facebook&lt;/code&gt; etc..., asking to reload or upgrade after deployment, no right ? how the hell are they doing the updates ?&lt;/p&gt;




&lt;h3&gt;
  
  
  Making sure we have cache invalidated in CDN
&lt;/h3&gt;

&lt;p&gt;Cache busting solves the CDN caching issue by using a unique file version identifier.&lt;br&gt;
As discussed in the &lt;a href="https://dev.to/mnathani/how-to-cache-frontend-app-1kkj"&gt;previous article&lt;/a&gt; we used &lt;code&gt;no-cache&lt;/code&gt; policies on some files to bust the cache using unique files names. Hence we are sure that &lt;code&gt;cloudfront&lt;/code&gt; will always keep the updated files..&lt;/p&gt;


&lt;h3&gt;
  
  
  Lets bust the browser cache
&lt;/h3&gt;

&lt;p&gt;So today will cover what is the one of the best approach to seamlessly bust the cache of the frontend application in the browsers when a deployment is done, without the user feeling the app was upgraded...&lt;/p&gt;
&lt;h4&gt;
  
  
  The trick
&lt;/h4&gt;

&lt;p&gt;The trick is we keep updating the version of the application in &lt;code&gt;meta&lt;/code&gt; file, which &lt;strong&gt;never&lt;/strong&gt; gets cached... and to seamlessly upgrade, we perform a &lt;strong&gt;reload&lt;/strong&gt; on the &lt;strong&gt;route change&lt;/strong&gt; so that user would feel as if they are redirecting to a different view, but in our case we are actually cache busting our application to get the new update from the &lt;code&gt;build&lt;/code&gt; we deployed.&lt;/p&gt;

&lt;p&gt;Let's dig in to see how its possible.&lt;/p&gt;
&lt;h4&gt;
  
  
  How to check if a new build is generated
&lt;/h4&gt;

&lt;p&gt;To know when we have a new build in browsers we keep two version of the application.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;package.json&lt;/code&gt; version&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;meta.json&lt;/code&gt; version&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  What are these version and how we manage it
&lt;/h4&gt;

&lt;p&gt;Here is the command &lt;code&gt;prebuild&lt;/code&gt; that runs before every &lt;code&gt;build&lt;/code&gt; to manage both versions as shown below:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;release&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;HUSKY=0 standard-version&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;prebuild&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;npm run release &amp;amp;&amp;amp; node ./build-version&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;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;package.json&lt;/code&gt; version is kept and maintain using tools like &lt;a href="https://semver.org/" rel="noopener noreferrer"&gt;Semantic versioning&lt;/a&gt; or &lt;a href="https://github.com/conventional-changelog/standard-version" rel="noopener noreferrer"&gt;Standard release&lt;/a&gt; which upgrades the package version after every deployment. Here we are using &lt;code&gt;standard-version&lt;/code&gt; to always get our &lt;code&gt;package.json&lt;/code&gt; upgraded. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;meta.json&lt;/code&gt; version is created in &lt;code&gt;public&lt;/code&gt; folder using a script &lt;code&gt;build-version.js&lt;/code&gt; we wrote to make sure we always get a latest version after deployment.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;build-version.js&lt;/code&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;const&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fs&lt;/span&gt;&lt;span class="dl"&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;version&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./package.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./public/meta.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;version&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;utf8&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;error&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;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error occurred on generating meta.json:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&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="c1"&gt;// eslint-disable-next-line no-console&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`meta.json updated with latest version: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;version&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="p"&gt;});&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;The above scripts takes the latest &lt;code&gt;version&lt;/code&gt; from &lt;code&gt;package.json&lt;/code&gt; which was upgraded using &lt;code&gt;npm run release&lt;/code&gt; and save it to &lt;code&gt;meta.json&lt;/code&gt; using &lt;a href="https://nodejs.dev/learn/writing-files-with-nodejs" rel="noopener noreferrer"&gt;fs.writeFile&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here is how the output of the above script will look like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;meta.json&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"108.0.0"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;


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

&lt;/div&gt;
&lt;p&gt;Before we proceed to the next step, let me inform you that we are using the following frameworks in our app:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reactjs: &lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;react&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Routing:  &lt;a href="https://v5.reactrouter.com/web/guides/quick-start" rel="noopener noreferrer"&gt;react-router-dom&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Code to check application is upgraded
&lt;/h4&gt;

&lt;p&gt;We created a hook that could be placed in a suitable position in your application, preferably on layouts/routes:&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useLocation&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;version&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../../../package.json&lt;/span&gt;&lt;span class="dl"&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;useCacheBuster&lt;/span&gt; &lt;span class="o"&gt;=&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="nx"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useLocation&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;parseVersion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\D&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&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="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`/meta.json?v=&lt;/span&gt;&lt;span class="p"&gt;${&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;Date&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="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;no cache&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="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="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="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;meta&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;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;version&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;metaVersion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseVersion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;version&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;packageVersion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseVersion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;version&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;packageVersion&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;metaVersion&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="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;reload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reload&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;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;error&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;something went wrong fetching meta.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&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="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;useCacheBuster&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;The hooks above is doing the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org/docs/hooks-effect.html" rel="noopener noreferrer"&gt;useEffect&lt;/a&gt; having a &lt;code&gt;deps&lt;/code&gt; of &lt;code&gt;location&lt;/code&gt;, which runs on every change of the route.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;parseVersion&lt;/code&gt; is a pure function that can format the version like &lt;code&gt;"1.0.5"&lt;/code&gt; into a number &lt;code&gt;105&lt;/code&gt;, so we can compare the versions.&lt;/li&gt;
&lt;li&gt;On changing the app route, the hook fires and fetches &lt;code&gt;/meta.json&lt;/code&gt; files from the root of the app, important thing to note here is we are passing a &lt;strong&gt;date param:&lt;/strong&gt; and &lt;strong&gt;cache&lt;/strong&gt;, to make sure this &lt;a href="https://stackoverflow.com/a/9692722/4527878" rel="noopener noreferrer"&gt;file never returns the cached content on fetching&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Using the response of &lt;code&gt;meta.json&lt;/code&gt; we are checking if &lt;code&gt;packageVersion&lt;/code&gt; is less than &lt;code&gt;metaVersion&lt;/code&gt;, which means the new build has deployed and the browser is using the old cached build, so the app needs to reload.&lt;/li&gt;
&lt;li&gt;If the above condition is &lt;code&gt;true&lt;/code&gt; then reload it!.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: if you are using a CDN then you need to cache bust in CDN by adding the &lt;code&gt;meta.json&lt;/code&gt; to behaviours as shown &lt;a href="https://dev.to/mnathani/how-to-cache-frontend-app-1kkj"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;P.S&lt;/strong&gt;: we can optimize the fetching of meta, by conditionalizing it on certain routes rather then all.&lt;/p&gt;

&lt;p&gt;That's it folks..., all you need to perform cache bust in browser programmatically.   &lt;/p&gt;


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

&lt;p&gt;The solution above is useful for the scenarios when you have a frequent deployment to production.&lt;br&gt;
Moreover, in my understanding for apps used in webview or apps saved on homepage could also be similarly busted with different reload methods... &lt;/p&gt;



&lt;p&gt;Please feel free to comment on the approach, would love to hear your feedback on this.&lt;/p&gt;

&lt;p&gt;Regards.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/mnathani" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F72394%2Fc9117f05-e06d-428e-87d3-b97cf157d619.jpeg" alt="mnathani"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mnathani/plugin-to-make-micro-frontend-using-cra-425n" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Plugin to make micro frontend using create react app&lt;/h2&gt;
      &lt;h3&gt;Murtaza Nathani ・ Dec 26 '21&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#react&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#programming&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>devops</category>
    </item>
    <item>
      <title>How to Cache web app?</title>
      <dc:creator>Murtaza Nathani</dc:creator>
      <pubDate>Sun, 05 Jun 2022 12:54:36 +0000</pubDate>
      <link>https://dev.to/mnathani/how-to-cache-frontend-app-1kkj</link>
      <guid>https://dev.to/mnathani/how-to-cache-frontend-app-1kkj</guid>
      <description>&lt;p&gt;I would like to share my learning on how we were able &lt;strong&gt;to cache web app&lt;/strong&gt; and then &lt;strong&gt;bust the cache&lt;/strong&gt; on every deployment so that the users can experience the latest changes.&lt;/p&gt;




&lt;h3&gt;
  
  
  Why do we need to cache ?
&lt;/h3&gt;

&lt;p&gt;Well obviously why would you do the same work again, if you can save and reuse it.&lt;/p&gt;

&lt;p&gt;In other words, lets say you need something and have to travel a long distance, so you keep it somewhere near to access it quickly.&lt;/p&gt;




&lt;p&gt;Before I go into more details, would like to brief you on my tech stack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;React app&lt;/strong&gt; using &lt;a href="https://create-react-app.dev/" rel="noopener noreferrer"&gt;create-react-app&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Using aws &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html" rel="noopener noreferrer"&gt;&lt;strong&gt;s3&lt;/strong&gt;&lt;/a&gt; to upload and host the static build&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html" rel="noopener noreferrer"&gt;&lt;strong&gt;Cloudfront&lt;/strong&gt;&lt;/a&gt; to cache it on the edge locations, with &lt;code&gt;s3&lt;/code&gt; origins&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  How did we cached before and why it was not a good approach
&lt;/h2&gt;

&lt;p&gt;We have created a script that was used in our pipeline to deploy our app to &lt;code&gt;s3&lt;/code&gt;:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  What's happening in above script ?
&lt;/h3&gt;

&lt;p&gt;We are using aws cli to upload build to &lt;code&gt;s3&lt;/code&gt; using &lt;a href="https://docs.aws.amazon.com/cli/latest/reference/s3/sync.html#examples" rel="noopener noreferrer"&gt;s3 sync&lt;/a&gt; command which upsert and delete files.&lt;/p&gt;

&lt;p&gt;Important thing to notice is that we are handling the cache on &lt;code&gt;s3&lt;/code&gt; with &lt;code&gt;static&lt;/code&gt; folder being cached and rest is not.&lt;/p&gt;

&lt;p&gt;Well coming back to tech stack we are using &lt;code&gt;s3&lt;/code&gt; to upload builds and &lt;code&gt;cloudfront&lt;/code&gt; to cache, then why the hell are we using &lt;code&gt;s3&lt;/code&gt; to cache.. :D&lt;/p&gt;




&lt;h2&gt;
  
  
  How did we manage to change the approach
&lt;/h2&gt;

&lt;p&gt;Using one of the rule of &lt;strong&gt;SOLID&lt;/strong&gt; is &lt;a href="https://en.wikipedia.org/wiki/Single-responsibility_principle" rel="noopener noreferrer"&gt;single usability principle&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.cleancoder.com/" rel="noopener noreferrer"&gt;Robert C. Martin&lt;/a&gt; &lt;code&gt;describes it as:&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A class should have one, and only one, reason to change.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Using &lt;code&gt;s3&lt;/code&gt; to just upload the files, of what is purpose is like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nv"&gt;S3BUCKETNAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;else
    &lt;/span&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;ERROR: Failed to supply S3 bucket name
    &lt;span class="nb"&gt;exit &lt;/span&gt;1
&lt;span class="k"&gt;fi

&lt;/span&gt;aws s3 &lt;span class="nb"&gt;sync &lt;/span&gt;build/ s3://&lt;span class="nv"&gt;$S3BUCKETNAME&lt;/span&gt; &lt;span class="nt"&gt;--delete&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;and using &lt;code&gt;cloudfront&lt;/code&gt; to create &lt;a href="https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_CacheBehavior.html" rel="noopener noreferrer"&gt;Cache behavior&lt;/a&gt; using unique &lt;code&gt;path&lt;/code&gt; patterns in the order of priority to apply.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Feqn4gp5xwdmfoyz7g22q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Feqn4gp5xwdmfoyz7g22q.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As shown in the above image we created three behaviors, with its specific purposes to cache or not cache. Make note that &lt;code&gt;index.html&lt;/code&gt; is &lt;strong&gt;not cached&lt;/strong&gt; because its entry point of our app and we want this file to be always updated on new deployment, hence it will always refetch from &lt;code&gt;s3&lt;/code&gt; origin. &lt;/p&gt;

&lt;p&gt;Moreover, you can use existing cache policies provided by &lt;code&gt;AWS&lt;/code&gt; or create your own &lt;a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-cache-policies.html?icmpid=docs_cf_help_panel" rel="noopener noreferrer"&gt;here&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;P.S: if you want to use a cache header such as &lt;code&gt;no-cache&lt;/code&gt; in &lt;code&gt;CloudFront&lt;/code&gt; to perticular resource in &lt;code&gt;origin&lt;/code&gt;, then we can add headers to &lt;code&gt;s3 origin&lt;/code&gt;, as I couldn't find a equivalent way to do the following in &lt;code&gt;CloudFront&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws s3 &lt;span class="nb"&gt;cp &lt;/span&gt;build/index.html s3://&lt;span class="nv"&gt;$S3BUCKETNAME&lt;/span&gt;/index.html &lt;span class="nt"&gt;--cache-control&lt;/span&gt; no-cache
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, Note: &lt;code&gt;no-cache&lt;/code&gt; doesn't mean "don't cache", it means it must check (or "revalidate" as it calls it) with the server before using the cached resource.&lt;/p&gt;

&lt;h4&gt;
  
  
  Further reading
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://jakearchibald.com/2016/caching-best-practices" rel="noopener noreferrer"&gt;Caching-best-practices&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And basically that's it folks!, this is all we needed to manage cache using dashboard of &lt;code&gt;cloudfront&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Cache Busting
&lt;/h2&gt;

&lt;p&gt;Well one of advantages of using &lt;code&gt;build&lt;/code&gt; produced from &lt;code&gt;CRA&lt;/code&gt; is that it generates a unique hash with file names which automatically gets cache busted on &lt;code&gt;cloudfront&lt;/code&gt; when we upload to &lt;code&gt;s3&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Well another approach to cache busting is invalidating the cache, which is not a good approach as it's relatively slow, and could get expensive fast seeing as &lt;code&gt;cloudfront&lt;/code&gt; gives you just &lt;code&gt;1,000&lt;/code&gt; free invalidation's per month, and then charges &lt;code&gt;$0.005&lt;/code&gt; per invalidation path requested as at the date of writing.&lt;/p&gt;

&lt;p&gt;Besides, it’s pretty clear that &lt;a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html#Invalidation_Expiration" rel="noopener noreferrer"&gt;CloudFront recommends Object Versioning or unique file names over invalidation&lt;/a&gt;…&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you’ll want to update your files frequently, we recommend that you primarily use file versioning&lt;/p&gt;
&lt;/blockquote&gt;




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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Here we learned how to manage cache using &lt;code&gt;cloudfront&lt;/code&gt;, rather than writing your own &lt;code&gt;bash&lt;/code&gt; scripts and managing it&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Making full use of &lt;code&gt;cloudfront&lt;/code&gt; to update and reuse the cache policies between different &lt;code&gt;origins&lt;/code&gt; or &lt;code&gt;distributions&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can add your own regex as &lt;code&gt;path&lt;/code&gt; in cache behavior&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No need of invalidating cache, as its expensive and not a best approach&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Would love to hear your thoughts with this approach.&lt;br&gt;
Regards,&lt;/p&gt;

</description>
      <category>react</category>
      <category>s3</category>
      <category>cloudfront</category>
      <category>devops</category>
    </item>
    <item>
      <title>Two lines of CSS that boosts 7x rendering performance!</title>
      <dc:creator>Murtaza Nathani</dc:creator>
      <pubDate>Sun, 29 May 2022 09:45:04 +0000</pubDate>
      <link>https://dev.to/mnathani/two-lines-of-css-that-boosts-7x-rendering-performance-4mjd</link>
      <guid>https://dev.to/mnathani/two-lines-of-css-that-boosts-7x-rendering-performance-4mjd</guid>
      <description>&lt;p&gt;I'll cut the crap out and jump directly to the two line of css that you need to add to improve your performance by approx &lt;strong&gt;7x&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;content-visibility&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;contain-intrinsic-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="m"&gt;5000px&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;
  
  
  Why do you need this?
&lt;/h2&gt;

&lt;p&gt;Website's nowadays need to be optimal and performant, users on the web have very short attention span. According to &lt;a href="https://lawsofux.com/doherty-threshold/" rel="noopener noreferrer"&gt;Doherty threshold&lt;/a&gt; response time to be 400 milliseconds.&lt;/p&gt;

&lt;p&gt;Now imagine a website like Facebook,Instagram etc.. taking more time then the threshold ? No one would be coming back to these sites again.&lt;/p&gt;


&lt;h2&gt;
  
  
  When would you use this?
&lt;/h2&gt;

&lt;p&gt;Most common use cases for this is when you have huge list/grid of data that needs to render at the mount of the application.&lt;/p&gt;

&lt;p&gt;Example: Static website like specs or documentation or travel blogs etc...&lt;/p&gt;

&lt;p&gt;Would love hear in comments if you have any other use cases for it.&lt;/p&gt;


&lt;h2&gt;
  
  
  How does it work ?
&lt;/h2&gt;

&lt;p&gt;The browser acts smart by skipping rendering work with the class you applied with &lt;code&gt;content-visibility: auto&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Browser needs to know the layout of the DOM in order to render, those elements which are not in viewport are not rendered and infact have empty box with &lt;code&gt;contain-intrinsic-size&lt;/code&gt; you provided.&lt;/p&gt;

&lt;p&gt;To summarize all of the rendering is deferred until it reaches the viewport at which the browser renders the actual layout with the width, height and styles you provided.&lt;/p&gt;

&lt;p&gt;P.S: the layout which are not outside of the viewport would have a &lt;code&gt;height: 0&lt;/code&gt;, so when deferred layout comes to viewport it would stack on top of each other, so that's why &lt;code&gt;contain-intrinsic-size&lt;/code&gt; is needed, However, no worries these are just a fallback values, browser will render the actual ones when it renders in viewport.&lt;/p&gt;

&lt;p&gt;Hence one drawback of this is the scrollbars would be wacky and jump to places if the &lt;code&gt;contain-intrinsic-size&lt;/code&gt; not given properly. :) &lt;/p&gt;


&lt;h2&gt;
  
  
  Browser Support
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;content-visibility&lt;/code&gt; relies on the the &lt;a href="https://caniuse.com/css-containment" rel="noopener noreferrer"&gt;CSS Containment Spec&lt;/a&gt;. While &lt;code&gt;content-visibility&lt;/code&gt; currently is supported on mostly chromium tech as at the date of writing.&lt;/p&gt;

&lt;p&gt;However, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/content-visibility#browser_compatibility" rel="noopener noreferrer"&gt;&lt;code&gt;content-visibility&lt;/code&gt;&lt;/a&gt; support is not bad for a good to have feature on high end systems, however with progressing web development it will soon be supported in all browsers too. Hopefully :)&lt;/p&gt;


&lt;h2&gt;
  
  
  Alternatives
&lt;/h2&gt;

&lt;p&gt;There are alternatives to improve performance using JavaScript, such using &lt;a href="https://www.patterns.dev/posts/virtual-lists/" rel="noopener noreferrer"&gt;List virtualization&lt;/a&gt;, but who wants to write 100's of line of &lt;code&gt;js&lt;/code&gt; and maintain it when you could do it in &lt;em&gt;2 lines&lt;/em&gt; of &lt;code&gt;css&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Further reading; that you could do it in js:&lt;br&gt;
&lt;a href="https://react-window.vercel.app/#/examples/list/fixed-size" rel="noopener noreferrer"&gt;react-window&lt;/a&gt;&lt;br&gt;
&lt;a href="https://blog.logrocket.com/rendering-large-lists-with-react-virtualized-82741907a6b3/" rel="noopener noreferrer"&gt;react-virtualized&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Excellent demo and explanation:
&lt;/h2&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/FFA-v-CIxJQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;


&lt;h3&gt;
  
  
  Further readings:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://web.dev/content-visibility/#support" rel="noopener noreferrer"&gt;https://web.dev/content-visibility/#support&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/content-visibility" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/CSS/content-visibility&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Regards,&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/mnathani" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F72394%2Fc9117f05-e06d-428e-87d3-b97cf157d619.jpeg" alt="mnathani"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mnathani/best-way-to-learn-closure-in-javascript--29dp" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Best way to learn Closure in JavaScript ?&lt;/h2&gt;
      &lt;h3&gt;Murtaza Nathani ・ Jun 22 '22&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#programming&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>css</category>
      <category>performance</category>
      <category>html</category>
    </item>
    <item>
      <title>Plugin to make micro frontend using create react app</title>
      <dc:creator>Murtaza Nathani</dc:creator>
      <pubDate>Sun, 26 Dec 2021 07:36:55 +0000</pubDate>
      <link>https://dev.to/mnathani/plugin-to-make-micro-frontend-using-cra-425n</link>
      <guid>https://dev.to/mnathani/plugin-to-make-micro-frontend-using-cra-425n</guid>
      <description>&lt;p&gt;Hello everyone, I got inspired by how micro service works on backend and helps scale, manage and brings flexibility to develop apps. So i created a plugin that would help frontend to use micro apps.&lt;/p&gt;

&lt;h3&gt;
  
  
  This blog is divided into three parts:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Why did I create the plugin - The Purpose.&lt;/li&gt;
&lt;li&gt;What's micro-frontend. - The thing.&lt;/li&gt;
&lt;li&gt;How to use it. - Getting started.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  The purpose ✨ ?
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Convert your CRA project into a node library without ejecting or losing update support of react-scripts...&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Ummmm.. that sounds interesting.. but why ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well, my apps were used as a &lt;strong&gt;single page app&lt;/strong&gt; in a &lt;em&gt;WebView&lt;/em&gt; and also as &lt;strong&gt;node package&lt;/strong&gt; 📦 in a &lt;em&gt;react app&lt;/em&gt;.&lt;br&gt;
I was using &lt;strong&gt;ejected &lt;a href="https://create-react-app.dev/" rel="noopener noreferrer"&gt;create-react-app&lt;/a&gt;&lt;/strong&gt;. For which I had to customize &lt;a href="https://webpack.js.org/" rel="noopener noreferrer"&gt;webpack&lt;/a&gt; as a tool to build app for SPA and as a library.&lt;/p&gt;

&lt;p&gt;So far it was working fine, until apps grew... it was harder to manage and with time I have to keep updating the ejected cra dependencies and update webpack config for all the apps.. which is not a good practice and requires more resources to do it...&lt;/p&gt;

&lt;p&gt;So after research, found two best ways to do it&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://github.com/gsoft-inc/craco[](url)" rel="noopener noreferrer"&gt;craco&lt;/a&gt;&lt;/strong&gt;  &lt;em&gt;we chose this option&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vitejs.dev/" rel="noopener noreferrer"&gt;vite&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, there are pros and cons for choosing each, such as with &lt;em&gt;craco&lt;/em&gt; comes with its amazing loader and plugins and provide extensive community due to vast ecosystem of &lt;em&gt;webpack&lt;/em&gt; and CRA.. etc&lt;br&gt;
&lt;em&gt;vite&lt;/em&gt; is using &lt;em&gt;esbuild&lt;/em&gt; and is quite fast and less in size as compare to &lt;em&gt;webpack&lt;/em&gt;... etc&lt;/p&gt;


&lt;h3&gt;
  
  
  The thing 🎯
&lt;/h3&gt;

&lt;p&gt;Micro-frontend are a new pattern where web application UIs (frontends) are composed from semi-independent fragments that can be built by different teams same or using different technologies. &lt;/p&gt;

&lt;p&gt;Benefits of Micro Frontend Architecture&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Separation automation of CI/CD pipeline&lt;/li&gt;
&lt;li&gt;Team flexibility&lt;/li&gt;
&lt;li&gt;Single responsibility&lt;/li&gt;
&lt;li&gt;Reusability&lt;/li&gt;
&lt;li&gt;Technology agnosticism: Micro Frontend architecture is independent of technology. You can use components from different web development frameworks (React, Vue, Angular, etc.)&lt;/li&gt;
&lt;li&gt;Simple learning (Smaller modules are easier to learn and understand)&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  Getting started :the_horns::skin-tone-4:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/gsoft-inc/craco" rel="noopener noreferrer"&gt;Craco&lt;/a&gt;&lt;/strong&gt; is a api that overrides CRA and allowes to configure it. So using it I create a plugin called &lt;a href="https://www.npmjs.com/package/craco-plugin-micro-frontend" rel="noopener noreferrer"&gt;craco-plugin-micro-frontend&lt;/a&gt; that would build ours apps.&lt;/p&gt;

&lt;p&gt;Install it:&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;craco-plugin-micro-frontend &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Use the plugin into your &lt;code&gt;craco.config.js&lt;/code&gt; as below:&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;const&lt;/span&gt; &lt;span class="nx"&gt;microFrontedPlugin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;craco-plugin-micro-frontend&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&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;plugins&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="na"&gt;plugin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;microFrontedPlugin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;orgName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my-org&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my-app.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// should same as package main&lt;/span&gt;
        &lt;span class="na"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;src/index.injectable.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;//defaults to src/index.injectable.js,&lt;/span&gt;
        &lt;span class="na"&gt;orgPackagesAsExternal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// defaults to false. marks packages that has @my-org prefix as external so they are not included in the bundle&lt;/span&gt;
        &lt;span class="na"&gt;reactPackagesAsExternal&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="c1"&gt;// defaults to true. marks react and react-dom as external so they are not included in the bundle&lt;/span&gt;
        &lt;span class="na"&gt;externals&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="s1"&gt;react-router&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="s1"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="c1"&gt;// defaults to []. marks the specified modules as external so they are not included in the bundle&lt;/span&gt;
        &lt;span class="na"&gt;minimize&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="c1"&gt;// defaults to false, sets optimization.minimize value&lt;/span&gt;
        &lt;span class="na"&gt;libraryTarget&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;commonjs2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// defaults to umd&lt;/span&gt;
        &lt;span class="na"&gt;outputPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dist&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;customJestConfig&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt; &lt;span class="c1"&gt;// custom jest configurations&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;p&gt;NOTE: &lt;code&gt;src/index.injectable.js&lt;/code&gt; is a wrapper around the react App file so that it would be separated from &lt;code&gt;src/index.js&lt;/code&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Update the &lt;code&gt;package.json&lt;/code&gt; scripts section of your app as follows:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"main"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"my-app.js"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"files"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"dist/**"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"craco start"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"craco build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"build:lib"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"REACT_APP_INJECTABLE=true craco build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"craco test"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"coverage"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npm run test -- --coverage --watchAll=false --passWithNoTests"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"coverage:browser"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npm run coverage &amp;amp;&amp;amp; open coverage/lcov-report/index.html"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"analyze"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"REACT_APP_INTERACTIVE_ANALYZE=true npm run build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;This plugin helped me manage the build process and made my life easier.. Now that &lt;a href="https://github.com/facebook/create-react-app" rel="noopener noreferrer"&gt;CRA&lt;/a&gt; new version is release to &lt;a href="https://github.com/facebook/create-react-app/releases/tag/v5.0.0" rel="noopener noreferrer"&gt;v5&lt;/a&gt; all I have to to do is update dependencies of &lt;a href="https://github.com/m-nathani/craco-plugin-micro-frontend" rel="noopener noreferrer"&gt;craco-plugin-micro-frontend&lt;/a&gt; and it would update &lt;code&gt;react-scripts&lt;/code&gt; to v5, thus all my app will upgraded too.&lt;/p&gt;

&lt;p&gt;&lt;del&gt;P.S: &lt;a href="https://www.npmjs.com/package/craco-plugin-micro-frontend" rel="noopener noreferrer"&gt;craco-plugin-micro-frontend&lt;/a&gt; is waiting for @craco to update its peer deps to &lt;code&gt;react-script: "5.0.0"&lt;/code&gt; Further information at: &lt;a href="https://github.com/gsoft-inc/craco/issues/353" rel="noopener noreferrer"&gt;craco-issue&lt;/a&gt;&lt;/del&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  NOTE
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/craco-plugin-micro-frontend" rel="noopener noreferrer"&gt;craco-plugin-micro-frontend&lt;/a&gt; now fully supports &lt;code&gt;react-script: "5.0.0"&lt;/code&gt; 🥳 &lt;/p&gt;



&lt;p&gt;Here is the repo for the &lt;a href="https://github.com/m-nathani/react-bootstrap" rel="noopener noreferrer"&gt;demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thats it, thanks!&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/mnathani" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F72394%2Fc9117f05-e06d-428e-87d3-b97cf157d619.jpeg" alt="mnathani"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mnathani/how-to-cache-frontend-app-1kkj" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;How to Cache web app?&lt;/h2&gt;
      &lt;h3&gt;Murtaza Nathani ・ Jun 5 '22&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#react&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#s3&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#cloudfront&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#devops&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



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