<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: nikhil sharma</title>
    <description>The latest articles on Forem by nikhil sharma (@sharma2288).</description>
    <link>https://forem.com/sharma2288</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%2F787035%2F2a774fe4-af78-4ab3-806c-bc27a8cdbfd7.png</url>
      <title>Forem: nikhil sharma</title>
      <link>https://forem.com/sharma2288</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sharma2288"/>
    <language>en</language>
    <item>
      <title>Get JavaScript Objects from a JSON File</title>
      <dc:creator>nikhil sharma</dc:creator>
      <pubDate>Tue, 11 Jan 2022 06:44:09 +0000</pubDate>
      <link>https://forem.com/sharma2288/get-javascript-objects-from-a-json-file-2c86</link>
      <guid>https://forem.com/sharma2288/get-javascript-objects-from-a-json-file-2c86</guid>
      <description>&lt;h4&gt;
  
  
  Introduction
&lt;/h4&gt;

&lt;p&gt;JSON stands for JavaScript Object Notation.JSON is a lightweight format for storing and transporting data.JSON is often used when data is sent from a server to a web page.JSON is "self-describing" and easy to understand. JavaScript objects are an integral part of the React app, so they need to get accessed from JSON files/data to be uses in components.&lt;/p&gt;

&lt;p&gt;This blog will demonstrate how to get a JavaScript object from a JSON file or access it using a fetch() HTTP request.&lt;/p&gt;

&lt;h4&gt;
  
  
  Rendering Values from a JSON File
&lt;/h4&gt;

&lt;p&gt;Create one sample JSON file as given below, and save it as data.json&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="p"&gt;{&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;employees&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;employee1&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;firstName&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;John&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;lastName&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;Doe&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;employee2&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;firstName&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;Anna&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;lastName&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;Smith&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;employee3&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;firstName&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;Peter&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;lastName&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;Jones&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you want to render any of the key-value pairs from the JSON, the .map() function would be useful to iterate the objects; the example is 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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&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="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Import local JSON file&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Data&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./data&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="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Sample&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&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="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Using&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h3&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keys&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="nx"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&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;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;i&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;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Key&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="p"&gt;))}&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Sample&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In the above example, to use the local JSON file needs to be consumed using the import statement.&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;Data&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./data&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;p&gt;After that, you can access all the JSON data using Data in your component by using Object.keys() along with the .map() function.&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="p"&gt;{&lt;/span&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keys&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="nx"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using a local JSON file in the React app is a common approach when you want to render some static data, maintain server config, etc.&lt;/p&gt;

&lt;h4&gt;
  
  
  Rendering JSON Objects from an API Call
&lt;/h4&gt;

&lt;p&gt;You have seen the example where a local JSON file is used, but at the same time you may need to access JSON data from the server.&lt;/p&gt;

&lt;p&gt;Implement the API call as demonstrated 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="nx"&gt;componentDidMount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://jsonplaceholder.typicode.com/users&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;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&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="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nx"&gt;result&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;result&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="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="nx"&gt;log&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After implementing the API call, you can access the JSON data for the rendering 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="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&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="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Using&lt;/span&gt; &lt;span class="nx"&gt;API&lt;/span&gt; &lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h3&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&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="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&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="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&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;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;i&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;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Email&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;              &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="p"&gt;))}&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;Along with the state this.state.data, the additional function used is .map(), which iterates the array items from the state and renders them into the DOM.&lt;/p&gt;

&lt;p&gt;Hope ou enjoyed the blog post!!&lt;/p&gt;

&lt;p&gt;Please feel free to like, save and comment your thoughts!!&lt;/p&gt;

&lt;p&gt;Happy Reading!!!&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Making Sustainable Websites</title>
      <dc:creator>nikhil sharma</dc:creator>
      <pubDate>Sat, 08 Jan 2022 07:32:27 +0000</pubDate>
      <link>https://forem.com/sharma2288/making-sustainable-websites-4h21</link>
      <guid>https://forem.com/sharma2288/making-sustainable-websites-4h21</guid>
      <description>&lt;p&gt;Over the past few years, hundreds of people have died in climate change-related natural disasters all over the world and experts say it will only keep getting worse if measures are not taken.&lt;/p&gt;

&lt;p&gt;From summer of fire and record floods to freak frosts and locust invasions, experts say man-made climate change is wreaking havoc on the world's weather.&lt;/p&gt;

&lt;p&gt;But what does that have to do with web development?&lt;/p&gt;

&lt;p&gt;Should you as a web developer do anything, apart from putting your PC/Mac to sleep, when you leave it for lunch?&lt;/p&gt;

&lt;p&gt;Well, it's relevant for &lt;em&gt;everyone&lt;/em&gt;, but it's important for web developers, because we develop websites for the internet — &lt;strong&gt;that currently consumes 416.2TWh annually.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That's more energy than the entire UK!&lt;/p&gt;

&lt;p&gt;According to &lt;a href="https://websitecarbon.com/" rel="noopener noreferrer"&gt;Website Carbon&lt;/a&gt; :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The average web page tested produces 1.76 grams CO2 per page view. For a website with 10,000 monthly page views, that's 211 kg CO2 per year.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When you think of the major industries contributing to those emissions, few suspects that come to mind are energy, aviation, agriculture etc. But you will be surprised that global internet usage contributes to &lt;strong&gt;~3%&lt;/strong&gt; of global carbon emissions which is equivalent to carbon emissions of the entire aviation industry.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Did you know we need to cut by 60% of our net global emissions by 2060 to stabilize the climate and prevent catastrophic effects from global climate change? And that’s a conservative estimate.&lt;/p&gt;
&lt;/blockquote&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%2Fy42fx2l6d0ifn09lz6ra.jpg" 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%2Fy42fx2l6d0ifn09lz6ra.jpg" alt="Image showing pollution caused by industries"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Power Of Compounding
&lt;/h4&gt;

&lt;p&gt;In February of 2020, a web developer named Danny Von Kooten decided to update a popular Wordpress plugin that he created and maintains, &lt;a href="https://www.mc4wp.com/" rel="noopener noreferrer"&gt;Mailchimp for Wordpress&lt;/a&gt; . The change? Remove one, 20kb javascript dependency. The impact? &lt;a href="https://dannyvankooten.com/website-carbon-emissions/" rel="noopener noreferrer"&gt;An estimated reduction in global emissions of 59kg CO2&lt;/a&gt; per month.&lt;/p&gt;

&lt;p&gt;when you reduce complexity in one area, it compounds into others — a 20kb reduction in javascript isn’t &lt;em&gt;just _20kbs less for the end user — it’s 20kb less on the server, 20kb less on the CDN, 20kb less for the user, _and&lt;/em&gt;, in the case of Javascript (one of the most CPU-intensive assets we can serve on the web), many saved computational cycles. The net effect is far larger than the initial reduction.&lt;/p&gt;

&lt;h4&gt;
  
  
  Measure To Reduce Carbon Emissions
&lt;/h4&gt;

&lt;p&gt;Let's have a look at some of the things we can easily do:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose a green hosting provider&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To know whether you are using green hosting provider or not, you can visit &lt;a href="https://www.thegreenwebfoundation.org/" rel="noopener noreferrer"&gt;The Green Web Foundation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If your website is green, you receive a flair!&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%2Frwmsughfq2h9lwmumasz.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%2Frwmsughfq2h9lwmumasz.png" alt="Image showing green web foundation badge when website is using green hosting provider"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose a green CDN&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For CDN's, almost the same principles apply, as when choosing a hosting provider.&lt;/p&gt;

&lt;p&gt;You shouldn't have to worry about the location of the CDN, as most of them have locations all over the world, and thus will place your data close to it's core user base.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prevent battery-drain&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the website is heavy on Javascript and assets that will lead to faster discharge of battery. Here is where web developers can actually do something !&lt;/p&gt;

&lt;p&gt;Try to use Javascript only when needed.&lt;/p&gt;

&lt;p&gt;Javascript provides Observers that can greatly impact website like IntersectionObserver, MutationObserver, ResizeObserver, PerformanceObserver. Try to use these observers in scenarios applicable.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reduce network-traffic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;strong&gt;most important&lt;/strong&gt; thing you can do to lower your website carbon emissions, is by reducing the network-traffic on your site.&lt;/p&gt;

&lt;p&gt;Some of the implementations that we can do are &lt;strong&gt;use of lazy loading images, responsive images correctly, lazy loading videos, do not auto play videos, caching strategies.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simplify the user-journey&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I think everyone have tried to look for "shipping cost" on an ecommerce-site, and, not being able to find any relevant information, added an item to the basket.&lt;/p&gt;

&lt;p&gt;With _still _no info on "shipping-cost", I've personally then filled out dummy contact-details until I _finally _reached a page with the calculated shipping-cost — which were then too high, and I abandoned the site!&lt;/p&gt;

&lt;p&gt;I've no idea what the carbon emission footprint is for all these sites with miserable user-journeys, but I assume it's a lot!&lt;/p&gt;

&lt;p&gt;So, &lt;strong&gt;focus on simplifying the user journey and provide insights and information as easily as possible!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The web can be sustainable, and in making it sustainable, we can ensure that its treasures are available and accessible to all, now and into the future. The web is the largest, publicly-accessible library we have ever known. It’s worth asking ourselves — what can we do to make sure that it lasts, for generations to come?&lt;/p&gt;

&lt;h4&gt;
  
  
  Resources
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Test your own website at &lt;a href="http://www.websitecarbon.com/" rel="noopener noreferrer"&gt;websitecarbon.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://sustainablewebdesign.org/" rel="noopener noreferrer"&gt;Sustainablewebdesign.org&lt;/a&gt; is a fantastic resource, with detailed strategies you can employ as a designer, developer, or company leader.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://abookapart.com/products/sustainable-web-design/" rel="noopener noreferrer"&gt;A Book Apart&lt;/a&gt; has a whole book on it!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

&lt;p&gt;Please comment your thoughts on the same topic and how did you like the blog post!!&lt;/p&gt;

&lt;p&gt;Do like and save in case you find it interesting and helpful!!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>sustainability</category>
      <category>webdev</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Why Is Website Performance Important And Tricks To Improve Front End Performance</title>
      <dc:creator>nikhil sharma</dc:creator>
      <pubDate>Thu, 06 Jan 2022 10:04:08 +0000</pubDate>
      <link>https://forem.com/sharma2288/why-is-website-performance-important-and-tricks-to-improve-front-end-performance-f09</link>
      <guid>https://forem.com/sharma2288/why-is-website-performance-important-and-tricks-to-improve-front-end-performance-f09</guid>
      <description>&lt;h4&gt;
  
  
  WHY DOES PERFORMANCE MATTER:
&lt;/h4&gt;

&lt;p&gt;The performance of your website is important for accessibility and for other metrics that serve the goals of an organization or business. Web performance has a direct correlation to user experience, as well as the overall effectiveness of your site. A slow website can deter users and drive them to your competition. With this fast-evolving consumer behavior, one cannot risk overlooking the importance of website speed. You should care about web performance.&lt;/p&gt;

&lt;p&gt;Millions of different websites are browsed every day, and half of them users close in a few seconds without giving them a possibility to impress, share the content, or sell the goods they advertise. Why does it happen so? A big percentage of websites are sluggish, user-unfriendly, and browser-incompatible. Modern users are unlikely to spend their time on slow loading pages or poorly optimized websites. In the context of web services, such problems relate to poor front-end optimization. The goal of front-end performance is to give users an ability to get what they want from a website or an application at a very limited time and ensure that they have a smooth experience while interacting with it.&lt;/p&gt;

&lt;p&gt;Consider an example that you are running an e-commerce website. Performance is of major consideration as it is found that faster websites have lower shopping cart abandonment rates and higher conversion rates. For e-commerce websites, milliseconds in extra load time can result in loss of revenue.&lt;/p&gt;

&lt;p&gt;Similarly, in case of content websites like wikis or blogs, audience is everything. If your website is slow it results in higher bounce rates and lower search engine ranking. Now consider an example of intranet application like timesheet or internal portal a few seconds of load time might not be a big concern.&lt;/p&gt;

&lt;p&gt;Below are some interesting facts on business impacts and conversions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Etsy found that adding 160kb of hidden images to their mobile site increased their bounce rate by 12%.&lt;/li&gt;
&lt;li&gt;Walmart found that for every 1 second of improvement they experienced 2% increase in conversions.&lt;/li&gt;
&lt;li&gt;Amazon found that every 100 milliseconds in load time on amazon website resulted in 1% decrease in sales.&lt;/li&gt;
&lt;li&gt;Google found that when they increased the search results from 10 to 30, the load time increased by half a second and resulted in a 20% decrease in ad revenues.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Google has admitted that performance is one of the factors in their page rank algorithm. They recently began experimenting with red warning tags in search results, which is essentially a digital performance-based scarlet letter.&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%2F2zfn3km4bq32fuyqpop1.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%2F2zfn3km4bq32fuyqpop1.png" alt="Picture showing with slow label in google search results"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reference: &lt;a href="https://searchengineland.com/google-testing-red-slow-label-search-results-slower-sites-215483" rel="noopener noreferrer"&gt;https://searchengineland.com/google-testing-red-slow-label-search-results-slower-sites-215483&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lastly, let's consider the needs of our users and how performance fits into that.&lt;/p&gt;

&lt;p&gt;Users expect the software to be functional, reliable, usable, performant and pleasurable.&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%2Ftq53y1opcsqsbengfxnk.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%2Ftq53y1opcsqsbengfxnk.png" alt="Picture showing pyramid with functional, reliable, usable, performant and pleasurable"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below are a few statistics related to website speed. Hopefully this will help you understand why page speed plays an important role in meeting the website performance standards:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;40% of internet users are likely to abandon a website if it takes more than 3 seconds to load.&lt;/li&gt;
&lt;li&gt;50% of users expect a website to load in 2 seconds or less.&lt;/li&gt;
&lt;li&gt;70% of users that find your website to be slow will likely not return to your website again.&lt;/li&gt;
&lt;li&gt;45% of the users will share their poor experience with the page speed and website loading with others&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  PERFORMANCE METRICS:
&lt;/h4&gt;

&lt;p&gt;Performance metrics are the new standards of performance. There is no single metric or test that can be run on a site to evaluate how a user "feels". However, there are several metrics that can be "helpful indicators":&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First paint&lt;/strong&gt; - The time to start of first paint operation. Note that this change may not be visible; it can be a simple background color update or something even less noticeable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First Contentful Paint (FCP)&lt;/strong&gt; - The time until first significant rendering (e.g. of text, foreground or background image, canvas or SVG, etc.). Note that this content is not necessarily useful or meaningful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First Meaningful Paint (FMP)&lt;/strong&gt; - The time at which useful content is rendered to the screen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Largest Contentful Paint (LCP)&lt;/strong&gt; - The render time of the largest content element visible in the viewport.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Speed index&lt;/strong&gt; - Measures the average time for pixels on the visible screen to be painted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time to interactive&lt;/strong&gt; - Time until the UI is available for user interaction (i.e. the last long task of the load process finishes).&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%2Fqltozfqa9n369qewk1ji.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%2Fqltozfqa9n369qewk1ji.png" alt="Picture showing different performance web vitals with timings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reference: &lt;a href="https://business.trustedshops.com/blog/what-is-google-lighthouse" rel="noopener noreferrer"&gt;https://business.trustedshops.com/blog/what-is-google-lighthouse&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  TOOLS TO MEASURE PERFORMANCE:
&lt;/h4&gt;

&lt;p&gt;There are plenty of front-end performance tools out there (free and subscription-based) which allow you to audit the performance of your website and collect metrics covered in the previous section. Below are two tools I have used and highly recommend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1)&lt;/strong&gt; &lt;strong&gt;LIGHTHOUSE:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Google Lighthouse is a tool with which you can perform an audit on your website. You can use it as a simple Google Chrome extension or together with Chrome DevTools (this is a collection of web developer tools, directly in Chrome).&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%2Forzayvms94h2n36lolex.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%2Forzayvms94h2n36lolex.png" alt="Picture showing lighthouse tool"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reference: &lt;a href="https://developers.google.com/web/tools/lighthouse#:%7E:text=Lighthouse%20bookmark_border&amp;amp;text=Lighthouse%20is%20an%20open%2Dsource,web%20apps%2C%20SEO%20and%20more" rel="noopener noreferrer"&gt;https://developers.google.com/web/tools/lighthouse#:~:text=Lighthouse%20bookmark_border&amp;amp;text=Lighthouse%20is%20an%20open%2Dsource,web%20apps%2C%20SEO%20and%20more&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2) WEB PAGE TEST:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;WebPageTest.org is an open-source website performance testing tool that allows you to benchmark your website from one of their 40 locations and a wide range of devices. You can also choose to simulate your tests over a slow mobile network or a fast 4G network. The result will be graded from F to A and will include information on compression, time to first byte (TTFB), caching, waterfall charts for the resources load speed and more.&lt;/p&gt;

&lt;p&gt;It also features an option where it can run a test 3 times and display all three data sets. This helps figure out if the DNS or CDN might cause any delay and if the server can respond to all requests.&lt;/p&gt;

&lt;p&gt;It’s a great tool to get results on how your website is performing. It gives a detailed report and insights on several metrics and provides waterfall graph. We can monitor for trends and spikes. The waterfall chart gives insight into how assets and XHR calls are loading. Once we get the report, we can prioritize the impact and work towards addressing any issues.&lt;/p&gt;

&lt;p&gt;URL: webpagetest.org&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%2Fnlgke0no3ic7t7o5d3fo.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%2Fnlgke0no3ic7t7o5d3fo.png" alt="Picture showing web page test website"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3) GTmetrix&lt;/strong&gt;&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%2Fmcyzsn4i481e0hppnspg.jpg" 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%2Fmcyzsn4i481e0hppnspg.jpg" alt="Picture showing GTmetrix website"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GTmetrix allows you to get detailed information on your page speed, timings, performance score, and much more. GTmetrix also provides information about how to fix the issues that were exposed by the test.&lt;/p&gt;

&lt;p&gt;Without registering you can only run a test from one location Vancouver, Canada but after you sign up for a free account you’ll get to choose your location, different browsers, and even the connection type. This should paint a better picture of how your website works in different scenarios.&lt;/p&gt;

&lt;p&gt;There are several other open source and paid tools that can be used to measure performance. Here is a link that provides details of those - &lt;a href="https://sematext.com/blog/website-performance-speed-test-tools/#toc-3-google-pagespeed-insights-8" rel="noopener noreferrer"&gt;https://sematext.com/blog/website-performance-speed-test-tools/#toc-3-google-pagespeed-insights-8&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  TRICKS TO IMPROVE THE FRONT-END PERFORMANCE:
&lt;/h4&gt;

&lt;p&gt;This blog reveals front-end performance optimization tips that will definitely be useful to drastically improve front-end performance and enhance website speed to make sure the users won’t cut short their visit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1) Minification&lt;/strong&gt; Minification removes unnecessary characters from a file to reduce its size, thereby improving load times. When a file is minified, comments and unnecessary white space characters (space, newline, and tab) are removed. This improves response time since the size of the download is reduced.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2) Image Optimization&lt;/strong&gt; Images take up approximately 51% of the average web page size which can make websites heavy and slow. To reduce the image delivery time and boost the performance of a website, we recommend using responsive images. Responsive image techniques namely srcset, sizes, and elements allow the delivery of different scaled images based on the size and resolution of the accessing device. Check waterfall and identify ‘heavy’ assets taking the longest to load. Optimize the assets by compressing images and use of “srcset” attribute. WebP formatted images are approximately up to 30% smaller than JPEG and 25% smaller than PNG formatted images. Simply put, just converting the image into WebP format can significantly decrease the size of the web page. Just bear in mind that WebP format is not supported by Safari and iOS Safari.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3) Reduce number of requests&lt;/strong&gt; Latency has a substantial impact on mobile application performance. Reducing the number of unique objects on the page will help reduce sensitivity to latency. Waterfall of network requests shows various requests. Create sprite images that has images and use of SVG for vector assets.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4) Limit blocking requests&lt;/strong&gt; Browser is waiting for requests before initially rendering (blocking requests). JavaScript/CSS assets look to be the main offenders. Make use of “defer” or “async”. Use of media queries in CSS. When loading a page, during HTML parse, if the browser comes across an external script, like this …&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;script src="third-party-script.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;… the browser fetches the script asynchronously and then pauses rendering so it can be executed. This is bad because it slows the critical rendering path, which will result in a worse first contentful paint metric.&lt;/p&gt;

&lt;p&gt;The solution is to use the defer attribute, like below:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;script src="third-party-script.js" defer&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This instructs the browser to download the script as soon as it’s found, but it defers execution until after the HTML parsing is complete. This sidesteps the problem of delaying the critical rendering path and is the recommended way to load 3rd party scripts that manipulate the DOM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5) Increase the speed with caching&lt;/strong&gt; Caching stores a copy of the asset that a user has requested and later accesses the cached copy instead of the original copy. There are different types of caching that help to improve delivery speed: Browser cache. Files are stored in the browser local cache so when one wants to access them, there is no need to download them from a server. Cache server. Cache servers are located in different geographic regions so that the user’s requests don’t have to travel far. Memory cache. Memory cache helps to speed up the data delivery process within an application by storing certain parts of data in SRAM. Disc cache. Like a memory cache, disc cache stores data for it to be accessed faster within an application though it makes use of conventional RAM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6) Use a content delivery network (CDN)&lt;/strong&gt; The proximity of the mobile carrier's Internet gateway to web servers can impact response times. Using a CDN brings content to servers that are closer to the user, reducing latency and improving performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7) Remove unused CSS and JS&lt;/strong&gt; While loading or running a page, the coverage table in Google Chrome shows how much code was loaded and how much of it was actually used. The size of the pages can be reduced by only shipping the needed code. The process is the following: first, you load a page on Google Chrome, then use a coverage tool (in Dev Tools press Ctrl+Shift+P, type “Coverage”, press Drawer: Coverage). As soon as the page is reloaded, you can see how much unused code is there so you can find those modules and lazy load with import (). Then go to the coverage profile once again and confirm that it carries less code on initial load.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8) Lazy loading&lt;/strong&gt; Usually, when you load a web page, the browser requests all of its images regardless of whether they’re in the viewport or further down the page and out of sight. Lazy loading allows us to only load the images which are visible and asynchronously load the rest on-demand as the user scrolls. This reduces the number of requests on load and can speed up the process considerably. Trigger events/animation only once you scroll &amp;amp; lazy load the images.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9) Reduce the number of DOM elements&lt;/strong&gt; complex page means more bytes to download, and it also means slower DOM access in JavaScript. Httparchive.org reports an average of 1,300 DOM elements per page. Reduce the number of DOM elements on the page to improve performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10) Avoid empty SRC or HREF&lt;/strong&gt; You may expect a browser to do nothing when it encounters an empty image SRC tag. However, this isn't the case in most browsers. Safari will make a request to the actual page itself. This behavior could corrupt user data, waste server computing cycles generating a page that will never be viewed, and in the worst case, cripple your servers by sending a large amount of unexpected traffic.&lt;/p&gt;

&lt;p&gt;References: 1) &lt;a href="https://buttercms.com/blog/front-end-performance-optimization-techniques" rel="noopener noreferrer"&gt;https://buttercms.com/blog/front-end-performance-optimization-techniques&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2) &lt;a href="https://medium.com/@inverita/frontend-optimization-8-tips-to-improve-web-performance-29af4b00efe7" rel="noopener noreferrer"&gt;https://medium.com/@inverita/frontend-optimization-8-tips-to-improve-web-performance-29af4b00efe7&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3) &lt;a href="https://techbeacon.com/app-dev-testing/23-front-end-performance-rules-web-applications" rel="noopener noreferrer"&gt;https://techbeacon.com/app-dev-testing/23-front-end-performance-rules-web-applications&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  FINAL THOUGHTS:
&lt;/h4&gt;

&lt;p&gt;Hopefully, you now know a little more about why optimizing front-end web performance is important and how to accomplish it. Now you can make this a part of your standard workflow and see the considerable benefits for yourself. As you can probably there are a lot of options to choose from, each with its unique feature and it’s up to you to test them and figure out which one works best for you. And like Yoda once said to Luke:&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%2Fdwtbvu4afbwi187hel6m.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%2Fdwtbvu4afbwi187hel6m.gif" alt="Picture showing Yoda saying to Luke - "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lastly, there are also a whole list of other things you can do to improve performance that are specific to the framework you’re using (Ex: React, Angular, VUE). The list mentioned in the article is not an all-inclusive list.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>performance</category>
      <category>html</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
