<?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: Spruce Emmanuel</title>
    <description>The latest articles on Forem by Spruce Emmanuel (@spruceemma).</description>
    <link>https://forem.com/spruceemma</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%2F548457%2Fcc22a379-2bc9-4186-a94a-28f081acb587.png</url>
      <title>Forem: Spruce Emmanuel</title>
      <link>https://forem.com/spruceemma</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/spruceemma"/>
    <language>en</language>
    <item>
      <title>Day 04: Learning JavaScript APIs: Intersection Observer API</title>
      <dc:creator>Spruce Emmanuel</dc:creator>
      <pubDate>Tue, 31 Dec 2024 17:40:00 +0000</pubDate>
      <link>https://forem.com/spruceemma/day-04-learning-javascript-apis-intersection-observer-api-44a1</link>
      <guid>https://forem.com/spruceemma/day-04-learning-javascript-apis-intersection-observer-api-44a1</guid>
      <description>&lt;p&gt;You’re scrolling through YouTube or your favorite social media app, and content loads seamlessly as you scroll. Animations come to life just as you reach them. At first glance, building features like these might seem complex, but JavaScript provides a powerful tool that makes it surprisingly simple: the &lt;strong&gt;Intersection Observer API&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This API eliminates the need for manually tracking scroll events and calculating element positions. Instead, it offers a faster, more efficient way to handle visibility-based interactions. In this article, we’ll explore what the Intersection Observer API is, how it works, and some cool things you can build with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is the Intersection Observer API?
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Intersection Observer API&lt;/strong&gt; allows developers to track an element's visibility within the viewport (or any specified parent container). Think of it as a helpful observer that lets you know when the visibility of an element changes—whether it’s entering, exiting, or fully visible.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Does the Intersection Observer API Work?
&lt;/h2&gt;

&lt;p&gt;Using the Intersection Observer API boils down to two simple steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an observer.&lt;/li&gt;
&lt;li&gt;Attach it to elements you want to monitor.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. Creating an Observer
&lt;/h3&gt;

&lt;p&gt;To get started, you create an &lt;code&gt;IntersectionObserver&lt;/code&gt; instance. This takes two parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;callback&lt;/strong&gt; function, triggered when the visibility of the observed element changes.&lt;/li&gt;
&lt;li&gt;Optional &lt;strong&gt;observer options&lt;/strong&gt;, allowing you to fine-tune the behavior.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s an example:&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;observerOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;root&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Default: the viewport&lt;/span&gt;
  &lt;span class="na"&gt;threshold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Trigger when 50% of the element is visible&lt;/span&gt;
  &lt;span class="na"&gt;rootMargin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// No margin by default&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;observerCallback&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;entries&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;entries&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;entry&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;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isIntersecting&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;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is in view!`&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;observer&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;IntersectionObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observerCallback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;observerOptions&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Simplified Version
&lt;/h4&gt;

&lt;p&gt;The only required parameter is the callback function. If you skip the options, the defaults will apply:&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;observer&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;IntersectionObserver&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;entries&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;entries&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;entry&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;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isIntersecting&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;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is visible`&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;h3&gt;
  
  
  Understanding Observer Options
&lt;/h3&gt;

&lt;p&gt;To make the most out of this API, let’s break down the three main options:&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;1. root&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;By default, the observer tracks elements relative to the viewport. However, you can specify a custom parent element instead:&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="c1"&gt;// Default: viewport&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;observer&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;IntersectionObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Custom root&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;observerWithRoot&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;IntersectionObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;root&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.scroll-container&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;2. threshold&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The threshold determines how much of the element must be visible before the callback is fired. It can be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A single value (e.g., &lt;code&gt;0.5&lt;/code&gt; for 50% visibility).&lt;/li&gt;
&lt;li&gt;An array of values to trigger multiple callbacks.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Fire callback when 50% of the element is visible&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;observer&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;IntersectionObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;threshold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Fire callback at 25%, 50%, 75%, and 100% visibility&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;observerWithArray&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;IntersectionObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;threshold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;0.25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.75&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;3. rootMargin&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;rootMargin&lt;/code&gt; adds an invisible margin around the root. Think of it as a CSS margin that affects when the callback fires.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Positive values&lt;/strong&gt; expand the root’s boundaries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Negative values&lt;/strong&gt; shrink the root’s boundaries.
&lt;/li&gt;
&lt;/ul&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;observer&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;IntersectionObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;rootMargin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;20px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="c1"&gt;// Fires 20px *before* the element enters the viewport&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Observing Elements
&lt;/h3&gt;

&lt;p&gt;Once you’ve created the observer, attach it to the elements you want to monitor using &lt;code&gt;observe()&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;elements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.watch-me&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;elements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;observe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What Can You Build with the Intersection Observer API?
&lt;/h2&gt;

&lt;p&gt;This API is incredibly versatile. Here are some practical examples to inspire you:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Lazy Load Images
&lt;/h3&gt;

&lt;p&gt;Delay loading images until they are about to enter the viewport, improving performance:&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;lazyLoad&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;IntersectionObserver&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;entries&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;entries&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;entry&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;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isIntersecting&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;img&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Replace placeholder with actual image&lt;/span&gt;
      &lt;span class="nx"&gt;lazyLoad&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unobserve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;img&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Stop observing once loaded&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;img[data-src]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;img&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;lazyLoad&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;observe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;img&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Trigger Animations
&lt;/h3&gt;

&lt;p&gt;Play animations as elements come into view:&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;animateOnScroll&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;IntersectionObserver&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;entries&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;entries&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;entry&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;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isIntersecting&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;animate&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;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.animate-me&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;animateOnScroll&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;observe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Infinite Scrolling
&lt;/h3&gt;

&lt;p&gt;Load more content dynamically as users scroll:&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;loadMore&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;IntersectionObserver&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;entries&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;entries&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;entry&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;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isIntersecting&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;fetchMoreContent&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Your function to load more items&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;loadMore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;observe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.load-more-trigger&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;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;The Intersection Observer API is one of the best APIs JavaScript provides for modern web development. It makes managing visibility-based interactions simple, efficient, and elegant. Whether it’s lazy loading, triggering animations, or building infinite scroll, this API is a must-have tool in your development toolkit.&lt;/p&gt;

&lt;p&gt;Next time you’re tempted to rely on scroll events, try the Intersection Observer API instead and you’ll love how much cleaner and faster your code becomes!&lt;/p&gt;

&lt;p&gt;If you have any questions or want to share your thoughts, feel free to message me on Twitter at &lt;a href="https://x.com/sprucekhalifa" rel="noopener noreferrer"&gt;@sprucekhalifa&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;Until next time—happy coding! 🎉  &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 03: Learning JavaScript APIs: Page Visibility API</title>
      <dc:creator>Spruce Emmanuel</dc:creator>
      <pubDate>Sun, 29 Dec 2024 06:00:00 +0000</pubDate>
      <link>https://forem.com/spruceemma/day-03-learning-javascript-apis-page-visibility-api-58m4</link>
      <guid>https://forem.com/spruceemma/day-03-learning-javascript-apis-page-visibility-api-58m4</guid>
      <description>&lt;p&gt;Ever had a YouTube tutorial playing in one tab while you’re busy working in another, only to realize later that the video is still running? Most of the time, you don’t even remember which tab it’s playing from. And if you’re anything like me, you have too many tabs open to start hunting for it. That random video running in the background is silently draining your battery and consuming resources.  &lt;/p&gt;

&lt;p&gt;You don’t want the apps you build to work like that. Thankfully, JavaScript has the &lt;strong&gt;Page Visibility API&lt;/strong&gt;, which lets you detect when a user has switched away from your app’s tab. With it, you can pause unnecessary tasks and save your users' precious battery life.  &lt;/p&gt;

&lt;p&gt;Today, we’re going to learn all about the Page Visibility API: what it is, why it’s useful, and how you can use it to build better apps.  &lt;/p&gt;

&lt;p&gt;By the end of this article, you’ll walk away knowing exactly how to integrate this API into your projects.  &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What is the Page Visibility API?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Page Visibility API&lt;/strong&gt; is a browser feature that helps developers figure out if a webpage is visible or hidden to the user. When a user switches to another tab or minimizes the browser, this API triggers an event that can adjust your app’s behavior accordingly.  &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Why Use the Page Visibility API?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This API is incredibly handy in making your apps smarter. Here’s how it can help:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Pause Resource-Heavy Tasks&lt;/strong&gt;: Stop animations, videos, or timers when users aren’t actively viewing your app.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Save Battery Life&lt;/strong&gt;: Especially useful for mobile users with limited battery power.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improve User Experience&lt;/strong&gt;: Automatically resume paused tasks or even greet users when they return to your app.
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;How the Page Visibility API Works&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The API revolves around two key features:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;document.hidden&lt;/code&gt;&lt;/strong&gt;: A boolean that tells you whether the page is hidden (&lt;code&gt;true&lt;/code&gt;) or visible (&lt;code&gt;false&lt;/code&gt;).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;visibilitychange&lt;/code&gt; Event&lt;/strong&gt;: Fires whenever the visibility of the page changes.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s a basic example to show how it works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;visibilitychange&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="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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hidden&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;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;The page is hidden.&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="k"&gt;else&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;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;The page is visible.&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;When the user switches tabs or minimizes the browser, this event runs, logging whether the page is visible.  &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Things You Can Do with the Page Visibility API&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;1. Pause and Resume a Timer&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;If your app has a timer, you can use this API to pause it when the user switches tabs and resume it when they return.&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;let&lt;/span&gt; &lt;span class="nx"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;visibilitychange&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="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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;clearInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;timer&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;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Timer paused.&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="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;timer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setInterval&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;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Timer running...&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="mi"&gt;1000&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;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Timer resumed.&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;h4&gt;
  
  
  &lt;strong&gt;2. Greet Users When They Return&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Add a personalized touch to your app by welcoming users back when they return.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;visibilitychange&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="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="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Welcome back!&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;h4&gt;
  
  
  &lt;strong&gt;3. Optimize Resource Usage for Videos&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Make your app more efficient by pausing videos when the user leaves the page.&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;video&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;video&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;visibilitychange&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="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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;video&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pause&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;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Video paused.&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="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;video&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;play&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;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Video resumed.&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;h3&gt;
  
  
  &lt;strong&gt;Browser Support&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The Page Visibility API is well-supported across modern browsers like Chrome, Firefox, Edge, and Safari. For older browsers, you might want to implement a fallback.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Check Browser Compatibility:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
You can check compatibility on &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API#browser_compatibility" rel="noopener noreferrer"&gt;MDN’s Page Visibility API page&lt;/a&gt;.  &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Limitations&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;While this API is fantastic, it’s important to know its limits:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Not a Substitute for User Engagement&lt;/strong&gt;: The API only tells you if the page is visible—not if the user is actively interacting with it.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Behavior May Vary by Browser&lt;/strong&gt;: Some browsers may not fire the &lt;code&gt;visibilitychange&lt;/code&gt; event in all scenarios, so always test thoroughly.
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Wrapping Up&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The Page Visibility API might not be as popular as other JavaScript APIs, but it’s a powerful tool for improving performance and user experience. By pausing unnecessary tasks when your app isn’t in use, you’re not just saving resources—you’re building apps that respect your users’ devices and preferences.  &lt;/p&gt;

&lt;p&gt;If you have any questions or want to share your thoughts, feel free to message me on Twitter at &lt;a href="https://x.com/sprucekhalifa" rel="noopener noreferrer"&gt;@sprucekhalifa&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;Until next time—happy coding! 🎉  &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Day 02: Learning JavaScript APIs: Web Share API</title>
      <dc:creator>Spruce Emmanuel</dc:creator>
      <pubDate>Sat, 28 Dec 2024 11:28:50 +0000</pubDate>
      <link>https://forem.com/spruceemma/day-02-learning-javascript-apis-web-share-api-17eb</link>
      <guid>https://forem.com/spruceemma/day-02-learning-javascript-apis-web-share-api-17eb</guid>
      <description>&lt;p&gt;Tired of building custom sharing interfaces from scratch? Why go through all that hassle when JavaScript has a built-in tool that lets you tap into the native sharing features of your users' devices? Meet the Web Share API — a handy solution that makes sharing on the web a seamless experience.&lt;/p&gt;

&lt;p&gt;In this article, we’ll explore what the Web Share API does and how you can use it to share text, links, and files directly from your web apps.&lt;/p&gt;

&lt;p&gt;So after reading this article you'll be working away with knowledge of the Web Share API and how to share various data from texts, to links and even files.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the Web Share API?
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Web Share API&lt;/strong&gt; is a browser feature that allows web applications to access the native sharing capabilities of a user's device. Want to send a link to WhatsApp? Share a file to an email client? All of this becomes effortless, and it works beautifully with mobile devices.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Things You Can Share Using This API
&lt;/h2&gt;

&lt;p&gt;Let’s look at three ways to use the Web Share API:  &lt;/p&gt;

&lt;h3&gt;
  
  
  1. Sharing Text
&lt;/h3&gt;

&lt;p&gt;Sharing text is straightforward. Here’s a simple example:  &lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"shareText"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Share Text&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;shareTextButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;shareText&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;shareTextButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&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="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="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;share&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;share&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Check out this cool text I just shared using the Web Share API!&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;span class="nf"&gt;then&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Text shared successfully!&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="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="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 sharing text:&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="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Your browser does not support the Web Share API.&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;&lt;strong&gt;Preview:&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd59q28ojpcike5t0z946.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd59q28ojpcike5t0z946.png" alt="A button labeled " width="674" height="766"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Sharing Links
&lt;/h3&gt;

&lt;p&gt;Want to let users share a link? It’s just as simple:  &lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"shareLink"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Share Link&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;shareLinkButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;shareLink&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;shareLinkButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&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="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="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;share&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;share&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Check out this link!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Here’s something interesting:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com&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;span class="nf"&gt;then&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Link shared successfully!&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="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="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 sharing link:&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="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Your browser does not support the Web Share API.&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;&lt;strong&gt;Preview:&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff1unmfpd8u7z6udlwj5l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff1unmfpd8u7z6udlwj5l.png" alt="A " width="674" height="766"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Sharing Files
&lt;/h3&gt;

&lt;p&gt;With &lt;strong&gt;Web Share API&lt;/strong&gt;, you can even share files. Here’s how users can pick files from their devices and share them:  &lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"file"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"fileInput"&lt;/span&gt; &lt;span class="na"&gt;multiple&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"shareFiles"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Share Files&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fileInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fileInput&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;shareFilesButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;shareFiles&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;shareFilesButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&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="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;files&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fileInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;files&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;files&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;===&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="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Please select files to share.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="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;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canShare&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;canShare&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;files&lt;/span&gt; &lt;span class="p"&gt;}))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;share&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;files&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sharing Files&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Here are some files I want to share with you.&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;span class="nf"&gt;then&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Files shared successfully!&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="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="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 sharing files:&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="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Your browser does not support file sharing with the Web Share API.&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;&lt;strong&gt;Preview:&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn2d0zyzxujx8e7ggoabj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn2d0zyzxujx8e7ggoabj.png" alt="A file input and " width="800" height="706"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Browser Compatibility
&lt;/h2&gt;

&lt;p&gt;The Web Share API is supported on most modern mobile browsers, but desktop support is still catching up. To avoid unpleasant surprises, use the &lt;code&gt;canShare&lt;/code&gt; method to check if the API supports what you’re sharing:  &lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canShare&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;canShare&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;files&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="p"&gt;([],&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;example.txt&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;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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;File sharing is supported!&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="k"&gt;else&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;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;File sharing is not supported on this browser.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For detailed browser compatibility, visit the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API#browser_compatibility" rel="noopener noreferrer"&gt;MDN Web Share API documentation&lt;/a&gt;.  &lt;/p&gt;




&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;The Web Share API is a game-changer for adding sharing functionality to your apps. By tapping into the native capabilities of users’ devices, it saves you development time while delivering a smooth, polished experience.&lt;/p&gt;

&lt;p&gt;So, the next time you’re tempted to build a custom sharing interface, let the Web Share API do the heavy lifting for you.&lt;/p&gt;

&lt;p&gt;And hey, if you have any questions, feel free to message me on Twitter at &lt;a href="https://x.com/sprucekhalifa" rel="noopener noreferrer"&gt;@sprucekhalifa&lt;/a&gt;. Don’t forget to follow me for more insights and updates.&lt;/p&gt;

&lt;p&gt;Happy coding! 🎉&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Learning JavaScript APIs: Console API</title>
      <dc:creator>Spruce Emmanuel</dc:creator>
      <pubDate>Fri, 27 Dec 2024 16:50:16 +0000</pubDate>
      <link>https://forem.com/spruceemma/day-01-learning-javascript-apis-console-api-ajc</link>
      <guid>https://forem.com/spruceemma/day-01-learning-javascript-apis-console-api-ajc</guid>
      <description>&lt;p&gt;JavaScript has a ton of built-in APIs that make programming fun and interesting. But let’s be real—how many of them do you actually use to their full potential? In this article, we’re diving into these APIs, covering what they are and the cool things you might’ve missed. From the basics to more advanced stuff, you’re bound to pick up some new tricks.&lt;/p&gt;

&lt;p&gt;Feeling overwhelmed by JavaScript APIs? Or maybe you’re just here to learn something new? Either way, this guide is for you.&lt;/p&gt;

&lt;p&gt;Let’s start with an API that’s been quietly helping you debug all along: the Console API. Sure, you’ve used console.log() before, but there’s so much more it can do. Let’s uncover some of its hidden tricks!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What is the Console API?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The Console API is a collection of super useful methods that make debugging, logging, and visualizing your data easier.  &lt;/p&gt;

&lt;p&gt;But let’s face it—you’ve probably been stuck on using &lt;code&gt;console.log()&lt;/code&gt; for everything. It’s time to break out of that habit because there’s so much more this API can do.  &lt;/p&gt;

&lt;p&gt;Here are some cool things you’ve been missing out on:  &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Cool Things You Can Do with the Console API&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Display Data in Tables&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Ever felt like your logs are just a mess of text you can’t make sense of? &lt;code&gt;console.table()&lt;/code&gt; has got your back.  &lt;/p&gt;

&lt;p&gt;Here’s what your logs probably look like right now:&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;fruits&lt;/span&gt; &lt;span class="o"&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;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Red&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="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Yellow&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="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Grapes&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Green&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;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;fruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz1ufqcs63mduc52pzphm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz1ufqcs63mduc52pzphm.png" alt="Cluttered log of an array of objects" width="800" height="53"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Now let’s clean that up:&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkm7g4knxb80mrx6irh0j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkm7g4knxb80mrx6irh0j.png" alt="Neat table showing name and color of fruits" width="800" height="316"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Much better, right? It’s easier to read, and now your data actually makes sense at a glance.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. &lt;strong&gt;Stop Writing Redundant If Statements with &lt;code&gt;console.assert()&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Raise your hand if you’ve written a dozen &lt;code&gt;if&lt;/code&gt; statements just to log errors. Well, stop doing that! &lt;code&gt;console.assert()&lt;/code&gt; is here to save the day.  &lt;/p&gt;

&lt;p&gt;Instead of this:&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;isLoggedIn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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;isLoggedIn&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;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;User is not logged in&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try this:&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;isLoggedIn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isLoggedIn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;User is not logged in&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;If the condition is &lt;code&gt;false&lt;/code&gt;, the message will be logged. So simple, right?&lt;/p&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;Measure Code Performance&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Curious about how long a block of code takes to execute? Say hello to &lt;code&gt;console.time()&lt;/code&gt; and &lt;code&gt;console.timeEnd()&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;Here’s how you can measure performance:&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Loop Timer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&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="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;_000_000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timeEnd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Loop Timer&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;&lt;strong&gt;Result:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn8c6d6r399rde5fxq8jf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn8c6d6r399rde5fxq8jf.png" alt="Console showing the time taken for the loop to run" width="800" height="35"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Now you can figure out what’s slowing down your app!&lt;/p&gt;
&lt;h3&gt;
  
  
  4. &lt;strong&gt;Count How Many Times a Block Runs&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Ever wondered how often a piece of code gets executed? Keeping track manually can be tricky, especially as your code grows more complex. That’s where &lt;code&gt;console.count()&lt;/code&gt; comes in handy.  &lt;/p&gt;

&lt;p&gt;Imagine this scenario:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greetUser&lt;/span&gt;&lt;span class="p"&gt;(&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&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&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;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&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="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;greetUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;greetUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;greetUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alex&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;greetUser&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first glance, it might be easy to figure out how many times the greeting runs for names starting with "A." But as your logic expands, you might lose track.  &lt;/p&gt;

&lt;p&gt;Now let’s simplify things with &lt;code&gt;console.count()&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greetUser&lt;/span&gt;&lt;span class="p"&gt;(&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&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&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Greeting users starting with A&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&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="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;greetUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;greetUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;greetUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alex&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;greetUser&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;countReset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Greeting users starting with A&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Reset the count&lt;/span&gt;

&lt;span class="nf"&gt;greetUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alice&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;&lt;strong&gt;Here’s What’s Happening:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every time a name starting with "A" is greeted, &lt;code&gt;console.count()&lt;/code&gt; increments the count and labels it "Greeting users starting with A."
&lt;/li&gt;
&lt;li&gt;After the reset with &lt;code&gt;console.countReset()&lt;/code&gt;, the count starts fresh.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No more guessing or adding print statements all over your code. Just one line, and you’ve got it covered!  &lt;/p&gt;

&lt;h3&gt;
  
  
  5. &lt;strong&gt;Style Your Logs with CSS&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Sometimes, you need your logs to pop. Use &lt;code&gt;%c&lt;/code&gt; to style your logs with CSS and make them stand out.  &lt;/p&gt;

&lt;p&gt;Example:&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;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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;%cWarning: This feature is deprecated!&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;color: white; background-color: red; font-size: 16px; padding: 4px; border-radius: 4px;&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;&lt;strong&gt;Result:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7d1j76q9yay8xbswh2s1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7d1j76q9yay8xbswh2s1.png" alt="Styled log with a red background and white text" width="800" height="51"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Highlight errors, warnings, or just have some fun with your logs.  &lt;/p&gt;
&lt;h3&gt;
  
  
  6. &lt;strong&gt;Group Related Logs Together&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Tired of scrolling through endless logs? Use &lt;code&gt;console.group()&lt;/code&gt; to group related logs together.  &lt;/p&gt;

&lt;p&gt;Here’s an example:&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;User Info&lt;/span&gt;&lt;span class="dl"&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;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;Name: John Doe&lt;/span&gt;&lt;span class="dl"&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;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;Age: 25&lt;/span&gt;&lt;span class="dl"&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;groupEnd&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;▼ User Info  
   Name: John Doe  
   Age: 25  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use &lt;code&gt;console.groupCollapsed()&lt;/code&gt; to keep groups collapsed by default.  &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Wrapping Up&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The Console API is a lot more powerful than you think. From tables to performance measurement, counters, styling, and grouping, there’s a tool for almost every debugging scenario.&lt;/p&gt;

&lt;p&gt;This is just Day 1 of our &lt;strong&gt;30 Days of JavaScript APIs&lt;/strong&gt; series. If you found this helpful, bookmark this article for later and be sure to stick around—there’s so much more to learn!   &lt;/p&gt;

&lt;p&gt;And hey, if you have any questions, feel free to message me on Twitter at &lt;a href="https://x.com/sprucekhalifa" rel="noopener noreferrer"&gt;@sprucekhalifa&lt;/a&gt;. Don’t forget to follow me for more insights and updates. Happy coding! &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Building SmartInbox: My Nylas Journey</title>
      <dc:creator>Spruce Emmanuel</dc:creator>
      <pubDate>Mon, 02 Sep 2024 06:43:05 +0000</pubDate>
      <link>https://forem.com/spruceemma/building-smartinbox-my-nylas-journey-34nm</link>
      <guid>https://forem.com/spruceemma/building-smartinbox-my-nylas-journey-34nm</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/nylas"&gt;Nylas Challenge&lt;/a&gt;: AI Expedition.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built and Why
&lt;/h2&gt;

&lt;p&gt;For this challenge, I built &lt;strong&gt;SmartInbox&lt;/strong&gt;, an AI-powered email assistant designed to integrate AI with the Nylas API, demonstrating how these technologies can work together. The core idea was to show how AI can be trained with a user's email data to provide accurate, context-aware summaries and smart replies using Retrieval-Augmented Generation (RAG).&lt;/p&gt;

&lt;h3&gt;
  
  
  Hosted Auth by Nylas
&lt;/h3&gt;

&lt;p&gt;To securely connect users' emails and obtain the necessary permissions, I used the hosted authentication provided by Nylas. This allows users to safely link their email accounts to SmartInbox. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi06mcg4l3to80a1xzdew.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi06mcg4l3to80a1xzdew.png" alt="Image description" width="800" height="559"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  AI Training with Custom Data
&lt;/h3&gt;

&lt;p&gt;SmartInbox allows users to train their AI model by uploading any email dataset of their choice. This training enhances the AI's ability to generate more relevant and accurate responses based on the user's unique email data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F11wxzuv6u9c67pjrn23j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F11wxzuv6u9c67pjrn23j.png" alt="Image description" width="800" height="559"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Specialized Summaries and Smart Replies
&lt;/h3&gt;

&lt;p&gt;Once the AI is trained, users can view their emails and receive specialized summaries and smart replies tailored to the context of each email. This feature highlights the potential of combining AI with the Nylas API to streamline email management.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu2erve8ikba0bnq82367.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu2erve8ikba0bnq82367.png" alt="Image description" width="800" height="559"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please note that since this is a demo project, the functionality to send emails has not been included.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;Check out this short video where I show the main features of SmartInbox and how it helps with email management. Training the AI Model with a large dataset might take a while when watching the demo.&lt;/p&gt;

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

&lt;p&gt;You can also view the &lt;a href="https://nylas-ai.vercel.app" rel="noopener noreferrer"&gt;project live here&lt;/a&gt; to explore its features firsthand.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;You can find the source code on &lt;a href="https://github.com/iamspruce/nylas-ai" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. This project is open source and available under the MIT license.&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9-wwsHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/iamspruce" rel="noopener noreferrer"&gt;
        iamspruce
      &lt;/a&gt; / &lt;a href="https://github.com/iamspruce/nylas-ai" rel="noopener noreferrer"&gt;
        nylas-ai
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;SmartInbox&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;SmartInbox is an AI-powered email assistant that helps you efficiently manage your emails. It provides intelligent email summaries and smart reply suggestions, allowing you to handle your inbox with ease.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Features&lt;/h2&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;AI-Powered Summaries&lt;/strong&gt;: Automatically generates concise summaries of opened emails, so you can quickly grasp the main points without reading through the entire message.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Smart Reply Suggestions&lt;/strong&gt;: Offers context-aware reply suggestions using Retrieval-Augmented Generation (RAG) based on your email data. This saves time by allowing you to respond to emails with just a click.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Training with Personal Email Data&lt;/strong&gt;: The AI assistant is trained using your own email data, ensuring that the summaries and suggestions are tailored to your specific communication style and preferences.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Getting Started&lt;/h2&gt;
&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Prerequisites&lt;/h3&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://nodejs.org/" rel="nofollow noopener noreferrer"&gt;Node.js&lt;/a&gt; (v14 or higher)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://nylas.com/" rel="nofollow noopener noreferrer"&gt;Nylas API Key&lt;/a&gt; for email integration&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.anthropic.com/" rel="nofollow noopener noreferrer"&gt;Anthropic API Key&lt;/a&gt; for AI capabilities&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://huggingface.co/" rel="nofollow noopener noreferrer"&gt;Hugging Face API Key&lt;/a&gt; for embedding models&lt;/li&gt;
&lt;li&gt;PostgreSQL database for storing user data…&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/iamspruce/nylas-ai" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  My Journey
&lt;/h2&gt;

&lt;p&gt;Creating SmartInbox was a great learning experience. I began by setting up a full-stack app using the &lt;a href="https://github.com/iamspruce/neon-oss-starter" rel="noopener noreferrer"&gt;NEON OSS Next.js Starter&lt;/a&gt;, which gave me a strong base. Then, I built an easy-to-use email dashboard with &lt;code&gt;shadcn/ui&lt;/code&gt; and connected Nylas for secure email authentication.&lt;/p&gt;

&lt;p&gt;Nylas was key in securely connecting to users' email accounts. It allowed me to fetch email data, which I then processed with an AI model.&lt;/p&gt;

&lt;p&gt;To make the AI work better, I trained it using public email datasets so it could give more accurate summaries and replies. I also used Claude AI to make the tool even smarter.&lt;/p&gt;

&lt;p&gt;During this project, I learned how AI can simplify handling emails and how to combine different APIs and machine learning tools. I'm proud of how it all came together to create a tool that helps people save time. This project has inspired me to keep exploring how AI can improve everyday tasks.&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>nylaschallenge</category>
      <category>api</category>
      <category>ai</category>
    </item>
    <item>
      <title>NEON OSS Next.js Starter Kit</title>
      <dc:creator>Spruce Emmanuel</dc:creator>
      <pubDate>Fri, 30 Aug 2024 09:52:34 +0000</pubDate>
      <link>https://forem.com/spruceemma/neon-oss-nextjs-starter-kit-1e6g</link>
      <guid>https://forem.com/spruceemma/neon-oss-nextjs-starter-kit-1e6g</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/neon"&gt;Neon Open Source Starter Kit Challenge &lt;/a&gt;: Ultimate Starter Kit&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  My Kit
&lt;/h2&gt;

&lt;p&gt;This is a powerful starter kit designed to kickstart your Next.js projects with ease. It comes fully equipped with authentication, Prisma integration, and a sleek UI using Tailwind CSS and Shadcn UI. Whether you're building a personal project or a full-scale application, this kit provides a solid foundation, including ready-to-go configurations for popular deployment platforms like Vercel, Netlify, and Heroku.&lt;/p&gt;

&lt;h2&gt;
  
  
  Link to Kit
&lt;/h2&gt;

&lt;p&gt;You can find my starter kit on GitHub: &lt;a href="https://github.com/iamspruce/neon-oss-starter" rel="noopener noreferrer"&gt;NEON OSS Starter Kit&lt;/a&gt;.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&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%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/iamspruce" rel="noopener noreferrer"&gt;
        iamspruce
      &lt;/a&gt; / &lt;a href="https://github.com/iamspruce/neon-oss-starter" rel="noopener noreferrer"&gt;
        neon-oss-starter
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      The NEON OSS Next.js Starter Kit is a full-stack application template designed to help developers kickstart their projects with modern technologies.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;NEON OSS Next.js Starter Kit&lt;/h1&gt;
&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Overview&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;The NEON OSS Starter Kit is a full-stack application template designed to help developers kickstart their projects with modern technologies. It features built-in user authentication, database management, and a fully responsive design, all powered by NEON, Next.js, Prisma, and Tailwind CSS. This starter kit is ideal for building scalable, serverless applications with ease, enabling you to focus on adding your unique features without worrying about the initial setup.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Tech Stack&lt;/h2&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://nextjs.org/" rel="nofollow noopener noreferrer"&gt;Next.js 14&lt;/a&gt;&lt;/strong&gt;: React framework for building web applications&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://neon.tech/" rel="nofollow noopener noreferrer"&gt;NEON&lt;/a&gt;&lt;/strong&gt;: Serverless PostgreSQL database&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.prisma.io/?via=spruce" rel="nofollow noopener noreferrer"&gt;Prisma&lt;/a&gt;&lt;/strong&gt;: Next-generation ORM for Node.js and TypeScript&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://next-auth.js.org/" rel="nofollow noopener noreferrer"&gt;NextAuth v5&lt;/a&gt;&lt;/strong&gt;: Authentication for Next.js&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://ui.shadcn.com/" rel="nofollow noopener noreferrer"&gt;shadcn/ui&lt;/a&gt;&lt;/strong&gt;: Re-usable components built with Radix UI and Tailwind CSS&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://tailwindcss.com/" rel="nofollow noopener noreferrer"&gt;Tailwind CSS&lt;/a&gt;&lt;/strong&gt;: Utility-first CSS framework&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Features&lt;/h2&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;User Authentication&lt;/strong&gt;: Includes sign-up, login, and logout functionality with protected routes for both client-side and server-side authentication, leveraging NextAuth.js.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database Management&lt;/strong&gt;: Integrated with Prisma for seamless…&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/iamspruce/neon-oss-starter" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;The repository includes detailed instructions on setting up the kit and getting started with your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your Journey
&lt;/h2&gt;

&lt;p&gt;I chose this stack because it combines the best tools for modern web development, making it easier to create robust, scalable applications. Through this process, I learned how to streamline the integration of various tools like Prisma, NextAuth, and Tailwind CSS, making them work together seamlessly. This project taught me the importance of simplicity and structure in a starter kit, ensuring that developers can focus on building their apps rather than getting lost in setup configurations.&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>neonchallenge</category>
      <category>postgres</category>
      <category>database</category>
    </item>
    <item>
      <title>Display: none; worsen or improve website performance?</title>
      <dc:creator>Spruce Emmanuel</dc:creator>
      <pubDate>Tue, 16 Feb 2021 15:03:04 +0000</pubDate>
      <link>https://forem.com/spruceemma/display-none-worsen-or-improve-website-performance-4m7d</link>
      <guid>https://forem.com/spruceemma/display-none-worsen-or-improve-website-performance-4m7d</guid>
      <description>&lt;p&gt;webDevs does &lt;b&gt;display: none;&lt;/b&gt; worsen website performance or improves it. 👇👇&lt;/p&gt;

</description>
      <category>css</category>
      <category>discuss</category>
      <category>webdev</category>
      <category>performance</category>
    </item>
    <item>
      <title>15 Ways To Use Google Like A Pro</title>
      <dc:creator>Spruce Emmanuel</dc:creator>
      <pubDate>Tue, 09 Feb 2021 00:00:00 +0000</pubDate>
      <link>https://forem.com/spruceemma/15-ways-to-use-google-like-a-pro-2j05</link>
      <guid>https://forem.com/spruceemma/15-ways-to-use-google-like-a-pro-2j05</guid>
      <description>&lt;p&gt;Googling is an Essential skill every web related person must have. In this guide i put together 15 ways to get better in Searching for content on the web&lt;/p&gt;

&lt;h2&gt;
  
  
  01. Google advanced search
&lt;/h2&gt;

&lt;p&gt;Google advanced search is one of the best google feature, you can narrow your results down to &lt;strong&gt;region&lt;/strong&gt; and when it was &lt;strong&gt;updated&lt;/strong&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  Try out The:
&lt;/h6&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://google.com/advanced_search" rel="noopener noreferrer"&gt;Google's advanced search for website and files&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://google.com/advanced_image_search" rel="noopener noreferrer"&gt;Google's advanced search for images&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://google.com/advanced_video_search" rel="noopener noreferrer"&gt;Google's advanced search for videos&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://google.com/advanced_book_search" rel="noopener noreferrer"&gt;Google's advanced search for books&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Oc6VE6t6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/15-ways-to-use-google-like-a-pro/img/advanced-search.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Oc6VE6t6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/15-ways-to-use-google-like-a-pro/img/advanced-search.png" alt="Google advanced search preview" width="800" height="475"&gt;&lt;/a&gt;&lt;br&gt;
    Google advanced search preview&lt;br&gt;
  &lt;/p&gt;

&lt;h2&gt;
  
  
  02. Finding Quick Definations
&lt;/h2&gt;

&lt;p&gt;Google does a great job in finding answers to your search word or phrases, like &lt;strong&gt;what is css&lt;/strong&gt; , but you can find the meaning of any word in google by adding &lt;strong&gt;Define&lt;/strong&gt; at the begining of the word  &lt;/p&gt;

&lt;p&gt;&lt;b&gt;Define Css&lt;/b&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  03. Perform Calculations
&lt;/h2&gt;

&lt;p&gt;You can also perform calculations in google as well by entering any maths equation like so&lt;/p&gt;

&lt;p&gt;30*800&lt;/p&gt;

&lt;h2&gt;
  
  
  04. Unit conversion
&lt;/h2&gt;

&lt;p&gt;Google also performs unit conversion just by entering any unit conversion in the search box&lt;/p&gt;

&lt;p&gt;200m to mm&lt;br&gt;&lt;br&gt;
100 dollers to naira&lt;/p&gt;

&lt;h2&gt;
  
  
  05. Searching for an exact image size
&lt;/h2&gt;

&lt;p&gt;Very useful when working with logos and when you need an image of specific file size, just add &lt;strong&gt;imagesize:500x400&lt;/strong&gt; at the begining of a word or phrase&lt;/p&gt;

&lt;p&gt;imagesize:500x400 spongeBob&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5ybUKR6i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/15-ways-to-use-google-like-a-pro/img/image-size.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5ybUKR6i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/15-ways-to-use-google-like-a-pro/img/image-size.png" alt="Exact 500x400 spongebob image" width="800" height="475"&gt;&lt;/a&gt;&lt;br&gt;
    Exact 500x400 spongebob image&lt;br&gt;
  &lt;/p&gt;

&lt;h2&gt;
  
  
  06. Search Social Media
&lt;/h2&gt;

&lt;p&gt;It is very easy to narrow a search to only social media in google, you can search only social media for a particular user or word in google by just adding &lt;strong&gt;@&lt;/strong&gt; at the begining of the word like&lt;/p&gt;

&lt;p&gt;@SpruceEmmanuel&lt;/p&gt;

&lt;h2&gt;
  
  
  07. Search For Hashtags
&lt;/h2&gt;

&lt;p&gt;You can also search for your favourite hashtags by just adding &lt;strong&gt;#&lt;/strong&gt; at the begining of the hashtag&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;#100daysOfCode&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  08. Search for Items with a specific prize
&lt;/h2&gt;

&lt;p&gt;Finding items that falls withing your budget is one of the coolest thing i like in Google, this can be acheived by simply adding the &lt;strong&gt;$&lt;/strong&gt; to the begining of the price&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Intro to python books $100&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  09. Exclude certain words from your search result
&lt;/h2&gt;

&lt;p&gt;This is done by adding an &lt;strong&gt;-&lt;/strong&gt; at the begining of the woed you want to exclude&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Create a blog with only html -css&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Searching for an exact match
&lt;/h2&gt;

&lt;p&gt;You can search for an exact match of a word or phrase by puting the word or phrase in qoute&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"What is Javascript"&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  11. Search within a range of numbers
&lt;/h2&gt;

&lt;p&gt;This is extremely useful when you have a minimum and maximum budget, you can Search for items price that are sold for &lt;strong&gt;$40 t0 200$&lt;/strong&gt; by adding &lt;strong&gt;...&lt;/strong&gt; between two numbers &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Javascript Cookbook $50...$100&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  12. Combining Search
&lt;/h2&gt;

&lt;p&gt;Add &lt;strong&gt;OR&lt;/strong&gt; between two search query to search for two items at at time. You can combine this with other search parameters to get more accurate search result, also notice that the "OR" is in uppercase &lt;/p&gt;

&lt;p&gt;Javascript Cookbook $50...$100 OR Python offline guide $40&lt;/p&gt;

&lt;h2&gt;
  
  
  13. Search a particular site
&lt;/h2&gt;

&lt;p&gt;You can search a specific site by adding &lt;strong&gt;site:&lt;/strong&gt; at the begining of a site or domain&lt;br&gt;&lt;br&gt;
site:spruce.com.ng&lt;br&gt;&lt;br&gt;
site:.dev&lt;/p&gt;

&lt;h2&gt;
  
  
  14. Search for a related site
&lt;/h2&gt;

&lt;p&gt;Check similar sites is possible in google by adding &lt;strong&gt;related:&lt;/strong&gt; at the begining of a site&lt;br&gt;&lt;br&gt;
related:spruce.com.ng&lt;/p&gt;

&lt;h2&gt;
  
  
  15. Google cached version of a site
&lt;/h2&gt;

&lt;p&gt;Can't find an article you once read on a site? you can always check the cache version of a site in google by adding &lt;strong&gt;cache&lt;/strong&gt; at the begining of a site&lt;br&gt;&lt;br&gt;
cache:spruce.com.ng&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>html</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>How to create 5 Cool css only Line effects</title>
      <dc:creator>Spruce Emmanuel</dc:creator>
      <pubDate>Fri, 01 Jan 2021 09:38:03 +0000</pubDate>
      <link>https://forem.com/spruceemma/how-to-create-5-cool-css-only-line-effects-4hi5</link>
      <guid>https://forem.com/spruceemma/how-to-create-5-cool-css-only-line-effects-4hi5</guid>
      <description>&lt;p&gt;Lines are always a great way to design our web pages, and lines ain't meant to be boring&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;
//Html
&amp;lt;div class="line"&amp;gt;&amp;lt;/div&amp;gt;

// Css
.line {
 border-bottom: 2px solid #ccc; // lines shouldn't be this boring
}
&lt;/code&gt;
&lt;/pre&gt;


&lt;h1&gt;
&lt;br&gt;
&lt;a href="%20https://spruce.com.ng/blog/how-to-create-5-css-only-line-effect.html"&gt;&lt;br&gt;
5 css only line effect &lt;/a&gt;

&lt;h2&gt;
Adding line to a text
&lt;/h2&gt;

&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PFakZx4c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/assets/img/posts/line-article.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PFakZx4c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/assets/img/posts/line-article.jpg" alt="line added to header text from smashingmagazine" width="480" height="99"&gt;&lt;/a&gt;&lt;/p&gt;

line added to header text from smashingmagazine





&lt;p&gt;Ever wanted to create something like that? 😊&lt;/p&gt;

&lt;p&gt;What if I told you that this can easily be achieved with a few lines of css&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;
 // HTML code
   &amp;lt;div class="line-before"&amp;gt;
     &amp;lt;span class="line-before__inner"&amp;gt;
     Latest posts
    &amp;lt;/span&amp;gt;
    &amp;lt;/div&amp;gt;

// Css 
.line-before__inner {
 position:relative;
 display:block;
 width:100%;
 color:#333;
 background-position:center;
 z-index:2;
 padding-left:calc(100px + 1em);
}

.line-before__inner::before {
 content:'';
 position:absolute;
 display:block;
 width:100px;
 height:1px;
 background-color:currentColor;
 left:0;
 top:50%
} 
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;And there you have, as simple as that...&lt;/p&gt;

&lt;h2&gt;
Other cool css only Line effects
&lt;/h2&gt;

&lt;p&gt;
&lt;a href="%20https://spruce.com.ng/blog/how-to-create-5-css-only-line-effect.html#highlight-text"&gt;
Highlight Text
&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;a href="%20https://spruce.com.ng/blog/how-to-create-5-css-only-line-effect.html#line-both-side"&gt;
Add line to both side of an Element
&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;a href="%20https://spruce.com.ng/blog/how-to-create-5-css-only-line-effect.html#wavy-line"&gt;
Css only Wavy line
&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;a href="%20https://spruce.com.ng/blog/how-to-create-5-css-only-line-effect.html#line-hover"&gt;
Animate line on hover
&lt;/a&gt;
&lt;/p&gt;

&lt;blockquote&gt;
This article was originally written &lt;a href="%20https://spruce.com.ng/blog/how-to-create-5-css-only-line-effect.html"&gt;here&lt;/a&gt;,
Find me online &lt;a href="https://spruce.com.ng/about/" rel="noopener noreferrer"&gt;here&lt;/a&gt;
&lt;/blockquote&gt;

</description>
      <category>css</category>
      <category>html</category>
    </item>
    <item>
      <title>Top 5 CSS methodologies in 2021</title>
      <dc:creator>Spruce Emmanuel</dc:creator>
      <pubDate>Mon, 28 Dec 2020 07:36:27 +0000</pubDate>
      <link>https://forem.com/spruceemma/top-5-css-methodologies-in-2021-an1</link>
      <guid>https://forem.com/spruceemma/top-5-css-methodologies-in-2021-an1</guid>
      <description>&lt;p&gt;Css is very difficult to manage when you are dealing with a large system, this is because Everything in css is Global...&lt;/p&gt;

&lt;p&gt;Over the years developers have tried to proofer solution to this CSS maintainability problems, and this as led to many developers creating their own css methodologies...&lt;/p&gt;

&lt;h1&gt;What are css methodologies?&lt;/h1&gt;

&lt;p&gt;css methodologies are systems that are formaly documented down that help us to auhor/write css as isolated modules, rather than just some long indivisible code.&lt;/p&gt;

&lt;h2&gt; Top 5 CSS methodologies in 2021 &lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Atomic Css&lt;/li&gt;
&lt;li&gt;BEM&lt;/li&gt;
&lt;li&gt;ITCSS&lt;/li&gt;
&lt;li&gt;SMACSS&lt;/li&gt;
&lt;li&gt;OOCSS&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Please note that this list is based on the survey from   &lt;a href="%20https://2020.stateofcss.com/en-US/technologies/methodologies/"&gt;The state of CSS 2020&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt; The Big Reveal &lt;/h3&gt;

&lt;p&gt;There is no &lt;b&gt;best CSS methodology&lt;/b&gt;, The one you just to use depends on you and the type of your project.&lt;/p&gt;

&lt;p&gt;This post was originally written here&lt;br&gt;
&lt;a href="%20https://spruce.com.ng/blog/top-5-css-methodologies-in-2021.html"&gt;Top 5 CSS methodologies in 2021&lt;/a&gt;&lt;br&gt;
...&lt;/p&gt;

</description>
      <category>css</category>
      <category>methodologies</category>
      <category>top</category>
    </item>
    <item>
      <title>Create A Blog On Your Mobile Phone Part 3</title>
      <dc:creator>Spruce Emmanuel</dc:creator>
      <pubDate>Mon, 21 Dec 2020 00:00:00 +0000</pubDate>
      <link>https://forem.com/spruceemma/create-a-blog-on-your-mobile-phone-part-3-1g3e</link>
      <guid>https://forem.com/spruceemma/create-a-blog-on-your-mobile-phone-part-3-1g3e</guid>
      <description>&lt;p&gt;Sad to announce the end of this "how to create a blog on your mobile phone series", well i know we have learned a lot of new things in this web series&lt;/p&gt;

&lt;h6&gt;
  
  
  Some things we have learned so far
&lt;/h6&gt;

&lt;ol&gt;
&lt;li&gt;what mobile blogging is&lt;/li&gt;
&lt;li&gt;how to create a free website on github with jekyll&lt;/li&gt;
&lt;li&gt;how to clone your website to your mobile phone&lt;/li&gt;
&lt;li&gt;how to run some basic Git Commands in your mobile phone&lt;/li&gt;
&lt;li&gt;and so many other things&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;incase you missed the other series, don't worry you can always go back and read them up&lt;/p&gt;

&lt;h6&gt;
  
  
  Link to previous series
&lt;/h6&gt;

&lt;p&gt;&lt;a href="https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone" rel="noopener noreferrer"&gt;Create a blog on your mobile phone part 1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2" rel="noopener noreferrer"&gt;Create a blog on your mobile phone part 2&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets go back to what we are really here for, blogging from your mobile phone&lt;/p&gt;

&lt;h1&gt;
  
  
  What is blogging
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Blogging&lt;/strong&gt; refers to writing, photography, and other media that is self-published online.&lt;/p&gt;

&lt;p&gt;So basically you know what blogging is all about, its a way for a lot of people to express their feelings and share there ideas online.&lt;/p&gt;

&lt;h2&gt;
  
  
  Blogging with jekyll
&lt;/h2&gt;

&lt;p&gt;your blog posts live in a directory called &lt;strong&gt;_posts&lt;/strong&gt; in the root of your site, so basically thats where you will add all your blog posts&lt;/p&gt;

&lt;p&gt;Your blog file names begin with "year-month-date-your-title.md"&lt;br&gt;&lt;br&gt;
so when creating your post, always follow the order &lt;strong&gt;Year&lt;/strong&gt; - &lt;strong&gt;month&lt;/strong&gt; - &lt;strong&gt;date&lt;/strong&gt; - &lt;strong&gt;title&lt;/strong&gt;.md&lt;/p&gt;

&lt;p&gt;for a detailed on how to write blog posts on jekyll please refer to this jekyll guide below   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://jekyllrb.com/docs/blog" rel="noopener noreferrer"&gt;Learn more about jekyll post&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Publishing your first post
&lt;/h3&gt;

&lt;p&gt;The first step is to open your spck editor, &lt;a href="https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone.html" rel="noopener noreferrer"&gt;The editor you downloaded in the first part of this series&lt;/a&gt;, open it and navigate to your _posts folder &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---5JNeLJ9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-mobile-blog-on-your-mobile-phone-part-3/img/spck-preview.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---5JNeLJ9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-mobile-blog-on-your-mobile-phone-part-3/img/spck-preview.png" alt="Jekyll _posts folder in spck editor" width="480" height="960"&gt;&lt;/a&gt;&lt;br&gt;
   _Posts folder looks like this&lt;br&gt;
  &lt;/p&gt;

&lt;p&gt;Go ahead and delete the post found there and create another one with   &lt;/p&gt;

&lt;p&gt;YEAR-MONTH-DAY-TITLE.md format&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d5rptTBX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-mobile-blog-on-your-mobile-phone-part-3/img/spck-post.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d5rptTBX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-mobile-blog-on-your-mobile-phone-part-3/img/spck-post.png" alt="new post in jekyll spck editor" width="480" height="960"&gt;&lt;/a&gt;&lt;br&gt;
  Add new file&lt;br&gt;
  &lt;/p&gt;

&lt;p&gt;After you created the post&lt;br&gt;&lt;br&gt;
add your layout and title like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9v79qnxc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-mobile-blog-on-your-mobile-phone-part-3/img/spck-edited.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9v79qnxc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-mobile-blog-on-your-mobile-phone-part-3/img/spck-edited.png" alt="Edit jekyll config file in spck editor" width="480" height="960"&gt;&lt;/a&gt;&lt;br&gt;
  Modify jekyll site on spck editor&lt;br&gt;
  &lt;/p&gt;

&lt;p&gt;Now you can add anything to your blog post, after all you are now a blogger, after you are done with writting your post, just go ahead and commit your changes and then push them online like we learned in our &lt;a href="https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2.html" rel="noopener noreferrer"&gt;previous post&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and there you have it, you just created your first post, go ahead and preview your new post online&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TE6xTHrl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-mobile-blog-on-your-mobile-phone-part-3/img/preview-mobile.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TE6xTHrl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-mobile-blog-on-your-mobile-phone-part-3/img/preview-mobile.png" alt="Jekyll image folder in spck editor" width="800" height="1395"&gt;&lt;/a&gt;&lt;br&gt;
  this is what your new website look like in a mobile view&lt;br&gt;
  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VbQibxqn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-mobile-blog-on-your-mobile-phone-part-3/img/preview-web.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VbQibxqn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-mobile-blog-on-your-mobile-phone-part-3/img/preview-web.png" alt="Jekyll image folder in spck editor" width="800" height="436"&gt;&lt;/a&gt;&lt;br&gt;
  this is what your new website look like in a pc view&lt;br&gt;
  &lt;/p&gt;

&lt;h4&gt;
  
  
  Previous posts from this series
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone.html" rel="noopener noreferrer"&gt;Create a blog on your mobile phone part 1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/blog/create-a-blog-on-your-mobile-phone-part-2"&gt;create a blog on rour mobile phone with jekyll part 2&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Other resources to learn from
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web" rel="noopener noreferrer"&gt;Getting Started With The Web&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://jekyllrb.com/tutorials/home/" rel="noopener noreferrer"&gt;Jekyll tutorials home&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://jekyllrb.com/docs/step-by-step/08-blogging/" rel="noopener noreferrer"&gt;Blogging in jekyll&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;thanks for reading....&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>serverless</category>
      <category>git</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Create A Blog On Your Mobile Phone Part 2</title>
      <dc:creator>Spruce Emmanuel</dc:creator>
      <pubDate>Mon, 21 Dec 2020 00:00:00 +0000</pubDate>
      <link>https://forem.com/spruceemma/create-a-blog-on-your-mobile-phone-part-2-49ga</link>
      <guid>https://forem.com/spruceemma/create-a-blog-on-your-mobile-phone-part-2-49ga</guid>
      <description>&lt;p&gt;Hello dear reader and welcome to the second part of this web series on how to create a website or blog right from your mobile phone.&lt;/p&gt;

&lt;h1&gt;
  
  
  Quick Recap
&lt;/h1&gt;

&lt;p&gt;Like i said this is the second part of this series, incase you missed the first part you can always go back and read it here:   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone/" rel="noopener noreferrer"&gt;Create a blog on your mobile phone part 1&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
Talking about reading the other article, You should really read that article up as this one is just building on what we learned in the orther article&lt;/p&gt;

&lt;p&gt;We learn't a few and very essentials things though:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;concept of mobile blogging&lt;/li&gt;
&lt;li&gt;how to create a free website/blog&lt;/li&gt;
&lt;li&gt;how to clone your website/blog to your mobile phone&lt;/li&gt;
&lt;li&gt;and quit a all lot of other things&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Don't just take my word for it, you should read it up yourself.&lt;/p&gt;
&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;Before you continue on this tutorial you should have at least a basic knowledge of the things listed below&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;HTML&lt;/li&gt;
&lt;li&gt;How the web works (refer to part 1)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Yep thats all you will be needing for this part of the series...&lt;/p&gt;
&lt;h3&gt;
  
  
  Welcome to jekyll
&lt;/h3&gt;

&lt;p&gt;If you are the curious type like me, you would have asked yourself, what is &lt;strong&gt;JEKYLL&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  What really is Jekyll?
&lt;/h4&gt;

&lt;p&gt;&lt;br&gt;
&lt;a href="https://jekyllrb.com/" rel="noopener noreferrer"&gt;Jekyll&lt;/a&gt; is a static site generator. it takes text written in your favorite markup language and uses layouts to create a static website. You can &lt;b&gt;tweak the sites's look and feel&lt;/b&gt;, URLs, the data displayed on the page and more &lt;br&gt;
&lt;/p&gt;

&lt;p&gt;From the defination you get the idea... Jekyll is just plain html text that are converted to static website's.&lt;br&gt;&lt;br&gt;
Well &lt;strong&gt;static&lt;/strong&gt; is the opposite of &lt;strong&gt;Dynamic&lt;/strong&gt; , think of jekyll as the opposite of Dynamic websites built on WordPress and other dynamic websites...&lt;br&gt;&lt;br&gt;
of course being static is one of the features i like about jekyll, being static means your pages load super fast, no third party content(You own your contents and codes), and easy set up and customization, like you create a website with just Html, Css and js, Jeez how super fast is that...&lt;/p&gt;

&lt;p&gt;In addition to all it's other cool features and plugins, it also uses the &lt;strong&gt;Shopify Liquid:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Lquid&lt;/strong&gt; is an open-source template language created by shopify and written in Ruby.   &lt;/p&gt;

&lt;p&gt;Did i also mention that jekyll and github are completely free?&lt;br&gt;&lt;br&gt;
Yep they sure are.&lt;/p&gt;
&lt;h5&gt;
  
  
  Resources to learn jekyll
&lt;/h5&gt;

&lt;p&gt;you can learn all about jekyll and liquid from the below links&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://jekyllrb.com/docs/" rel="noopener noreferrer"&gt;jekyll official documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://shopify.github.io/liquid/basics/introduction/" rel="noopener noreferrer"&gt;liquid official documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h6&gt;
  
  
  Intro to git
&lt;/h6&gt;

&lt;p&gt;What is git?   &lt;/p&gt;

&lt;p&gt;Git is a distributed version-control system for tracking changes in any set of files... and so on&lt;/p&gt;

&lt;p&gt;Basically git is just meant and used to &lt;strong&gt;commit&lt;/strong&gt; , pull and &lt;strong&gt;push&lt;/strong&gt; changes to your &lt;strong&gt;remote repository&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A lot of terminologies used here, dont worry about that, you will soon see them in action very soon, but before then let me introduce you to what they are and how they are connected to creating a site on your mobile phone&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;COMMIT:&lt;/strong&gt; this command is used to save your changes to your local repository (the site you cloned to your mobile phone in the part 1 of this series)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PUSH:&lt;/strong&gt; this command is used to push(as the name implies) all the files you have commited to your remote repository&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;REMOTE REPO:&lt;/strong&gt; This is a common repository that all team members use to exchange their changes. This repository is stored on a code hosting service like Github(That's where github comes in)&lt;/li&gt;
&lt;/ol&gt;
&lt;h6&gt;
  
  
  Conncecting the dots...
&lt;/h6&gt;

&lt;p&gt;You may be wondering, how does this have to do with blogging from mobile phone...&lt;br&gt;&lt;br&gt;
well from the explanations above, you only need two things&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Remote Repository&lt;/li&gt;
&lt;li&gt;A place to run Git commands from&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;you already have a remote repo, so you shouldn't worry about that, what i will introduce to you is &lt;strong&gt;how you can execute git commands on your mobile phone&lt;/strong&gt;&lt;/p&gt;
&lt;h6&gt;
  
  
  I guess we are done talking...
&lt;/h6&gt;

&lt;p&gt;Too much talk and explanations (I really hope you get the idea), now lets stop talking and start showing how things work&lt;/p&gt;

&lt;p&gt;Go ahead and lunch your spck editor, &lt;a href="https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-with-jekyll-on-github.html" rel="noopener noreferrer"&gt;[The one you downloaded on the previous post]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T-9GJoMH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/project-preview.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T-9GJoMH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/project-preview.png" alt="Jekyll project on spck editor" width="480" height="960"&gt;&lt;/a&gt;&lt;br&gt;
    Your cloned project should look like this&lt;br&gt;
  &lt;/p&gt;

&lt;p&gt;Now its time to upload your own contents   &lt;/p&gt;

&lt;p&gt;Scroll down to the images folder and select it&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e73uleWf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/project-img.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e73uleWf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/project-img.png" alt="Jekyll image folder in spck editor" width="480" height="960"&gt;&lt;/a&gt;&lt;br&gt;
   Image folder looks like this&lt;br&gt;
  &lt;/p&gt;

&lt;p&gt;Click on the three dots(menu of the image folder),and click on Upload File&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WjeZpDGN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/project-img-upload.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WjeZpDGN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/project-img-upload.png" alt="Jekyll upload image in Spck editor" width="480" height="960"&gt;&lt;/a&gt;&lt;br&gt;
    Click on upload file&lt;br&gt;
  &lt;/p&gt;

&lt;p&gt;Now upload a loving photo of your self, or your website logo..&lt;br&gt;&lt;br&gt;
Now its time to edit the config file and customize the site to display your own info&lt;/p&gt;

&lt;p&gt;Now close your image folder and look for and open the file called&lt;br&gt;&lt;br&gt;
&lt;strong&gt;_config.yml&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
when you open it, you should see something like this below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---oHrRcz7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/project-config.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---oHrRcz7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/project-config.png" alt="Jekyll Config file in spck editor" width="480" height="960"&gt;&lt;/a&gt;&lt;br&gt;
    Your config file looks like this&lt;br&gt;
  &lt;/p&gt;

&lt;p&gt;basically anything you edit here affects your site drastically, so be careful of what you touch in here&lt;/p&gt;

&lt;p&gt;First thing you should change is name, in your config file change your name&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
name: your name
#Change it to the name you want to use
#name: Spruce


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

&lt;/div&gt;



&lt;p&gt;Change the description too&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
description: web developer from somewhere
#Change it to anything you want, just dont make it too look (seo issues)
#description: web developer based in Edo, Nigeria


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

&lt;/div&gt;



&lt;p&gt;Do you remember the image you uploaded? yep you do, its time to use it. From the &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web" rel="noopener noreferrer"&gt;Getting Started With The Web&lt;/a&gt; you read in the first part of this series i assume you now know how the web work...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
avatar: https://....
#Change it to the file you uploaded earlier
avatar: /images/spruce.jpg #in my case


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

&lt;/div&gt;



&lt;p&gt;Edit your footer links, add your social media liks to the footer links&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
footer-links:
  dribble: dribble username
  email:
  facebook:
  ..... etc


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

&lt;/div&gt;



&lt;p&gt;Change your url to your site url&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
url: github-username.github.io
#where github username is changed to your username
url: sprucestatic.github.io #in my case 


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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Leave the baseurl feed empty if your site is "github-username.github.io", but if your site is "github-username/static-site-name" add "/static-site-name" to the baseurl&lt;br&gt;&lt;br&gt;
 but if you have followed this series from the beginning please leave baseurl empty... &lt;/p&gt;

&lt;p&gt;Now its time to use the Git commands we explained before now&lt;br&gt;&lt;br&gt;
in the &lt;strong&gt;spck editor&lt;/strong&gt;   &lt;/p&gt;

&lt;p&gt;Click on the last fork icon at the bottom of the editor&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3wkevvBZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/project-fork.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3wkevvBZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/project-fork.png" alt="fork icon in spck editor" width="468" height="121"&gt;&lt;/a&gt;&lt;br&gt;
    Click on the last fork icon to your right&lt;br&gt;
  &lt;/p&gt;

&lt;p&gt;Once you have click on the fork icon, you should see something that looks like the one below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SCy5s2_w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/project-commit.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SCy5s2_w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/project-commit.png" alt="Spck editor commit" width="480" height="960"&gt;&lt;/a&gt;&lt;br&gt;
    Click on the commit all&lt;br&gt;
  &lt;/p&gt;

&lt;p&gt;the next steps are easy&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click on Commit All&lt;/li&gt;
&lt;li&gt;Enter commit Message&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can enter anything in your commit message, but that dosen't mean you should just write a bunch of anything you think of, a commit message should briefly explain the changes you made to your project.&lt;/p&gt;

&lt;p&gt;Remember from our defination of commit, it just save the changes to your local computer, in our case your mobile phone, that is the changes wont reflect on the web just yet, Now that is where &lt;strong&gt;GIT PUSH&lt;/strong&gt; comes in the picture... Push as the name implies pushes your saved commit to your remote repo (the one hosted on github) so that people can view it on the web.&lt;/p&gt;

&lt;p&gt;As you might have noticed, editing, uploading and committing to your cloned project dosen't require any data Connection. But when pushing your changes, you need a data connection, So go ahead and switch on your data connection and follow the below steps&lt;/p&gt;

&lt;p&gt;To push your changes follow this steps:   &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click on the last fork icon again&lt;/li&gt;
&lt;li&gt;Click on push&lt;/li&gt;
&lt;li&gt;Click Ok&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jMhHgVDp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/project-pushing.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jMhHgVDp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/project-pushing.png" alt="Spck editor Git push on mobile" width="467" height="299"&gt;&lt;/a&gt;&lt;br&gt;
   Wait for it to push your changes&lt;br&gt;
  &lt;/p&gt;

&lt;p&gt;Boom and there you go, your websites should be live with your changes on the web in a minute...&lt;br&gt;&lt;br&gt;
Go ahead and preview your website&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v6UkgcfT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/preview-mobile.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v6UkgcfT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/preview-mobile.png" alt="Mobile Preview of your free website" width="480" height="960"&gt;&lt;/a&gt;&lt;br&gt;
    On mobile phone your site looks like this&lt;br&gt;
  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--elA7HVnZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/preview-web.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--elA7HVnZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone-part-2/img/preview-web.png" alt="Web Preview of your free website" width="800" height="436"&gt;&lt;/a&gt;&lt;br&gt;
    On a pc your site looks like this&lt;br&gt;
  &lt;/p&gt;

&lt;p&gt;Well thats the end of this part of the series... Next stop is &lt;strong&gt;Blogging&lt;/strong&gt; , Thanks for reading...&lt;/p&gt;

&lt;h6&gt;
  
  
  Previous parts of this series
&lt;/h6&gt;

&lt;p&gt;&lt;a href="https://spruce.com.ng/blog/create-a-blog-on-your-mobile-phone/" rel="noopener noreferrer"&gt;Create a blog on your mobile phone part 1&lt;/a&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>serverless</category>
      <category>startup</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
