<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: alyson farias</title>
    <description>The latest articles on DEV Community by alyson farias (@nosylasairaf).</description>
    <link>https://dev.to/nosylasairaf</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%2F897688%2F7fcf4393-c534-47fe-955c-962b02e105f1.jpg</url>
      <title>DEV Community: alyson farias</title>
      <link>https://dev.to/nosylasairaf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nosylasairaf"/>
    <language>en</language>
    <item>
      <title>How We Added IP-Based Language Detection in 5 Minutes</title>
      <dc:creator>alyson farias</dc:creator>
      <pubDate>Sun, 11 Jan 2026 13:27:44 +0000</pubDate>
      <link>https://dev.to/nosylasairaf/how-we-added-ip-based-language-detection-in-5-minutes-45a2</link>
      <guid>https://dev.to/nosylasairaf/how-we-added-ip-based-language-detection-in-5-minutes-45a2</guid>
      <description>&lt;h1&gt;
  
  
  How We Added IP-Based Language Detection in 3 Minutes
&lt;/h1&gt;

&lt;h2&gt;
  
  
  The Challenge
&lt;/h2&gt;

&lt;p&gt;You want your Next.js app to automatically detect the user's language based on their location. Sounds complex, right? You might think you need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Third-party IP geolocation APIs&lt;/li&gt;
&lt;li&gt;Complex database lookups&lt;/li&gt;
&lt;li&gt;Expensive geolocation services&lt;/li&gt;
&lt;li&gt;Additional API calls on every page load&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Reality: It's Actually Super Simple
&lt;/h2&gt;

&lt;p&gt;Modern hosting platforms like &lt;strong&gt;Vercel&lt;/strong&gt; and &lt;strong&gt;Cloudflare&lt;/strong&gt; already detect the user's country for every request. They include this information in request headers—completely free, with zero additional API calls!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution: 3 Simple Steps
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Create a Country-to-Language Mapper (2 minutes)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/lib/i18n/country-to-language.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getLanguageFromCountry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;countryCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;Language&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Map common countries to languages&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;BR&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;PT&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;countryCode&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ES&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;MX&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;AR&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;countryCode&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;es&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;IT&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;countryCode&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;it&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// ... and so on&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Default&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Add Middleware (2 minutes)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/middleware.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;NextRequest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;NextResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="c1"&gt;// Get country from headers (Vercel/Cloudflare provides this!)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;countryCode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;x-vercel-ip-country&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;countryCode&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;language&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mapCountryToLanguage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;countryCode&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cookies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;detected-lang&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;language&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&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;That's it! The middleware runs automatically on every request and sets a cookie.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Update Your I18n Provider (1 minute)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Read from cookie instead of defaulting&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cookieLang&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getLanguageFromCookie&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;detectedLang&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cookieLang&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Fallback to default&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why This Is Brilliant
&lt;/h2&gt;

&lt;p&gt;✅ &lt;strong&gt;Zero cost&lt;/strong&gt; - No API calls, no third-party services&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Zero latency&lt;/strong&gt; - Headers are already in the request&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Zero complexity&lt;/strong&gt; - Just read headers and map countries&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Works everywhere&lt;/strong&gt; - Vercel and Cloudflare both support this&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Non-intrusive&lt;/strong&gt; - Falls back gracefully if headers aren't available  &lt;/p&gt;

&lt;h2&gt;
  
  
  The Magic Headers
&lt;/h2&gt;

&lt;p&gt;When you deploy on &lt;strong&gt;Vercel&lt;/strong&gt;, you get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;x-vercel-ip-country&lt;/code&gt; - The user's country code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you use &lt;strong&gt;Cloudflare&lt;/strong&gt;, you get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cf-ipcountry&lt;/code&gt; - The user's country code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both platforms detect this automatically. No configuration needed!&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-World Flow
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;User from Brazil visits your site&lt;/li&gt;
&lt;li&gt;Vercel/Cloudflare adds &lt;code&gt;x-vercel-ip-country: BR&lt;/code&gt; header&lt;/li&gt;
&lt;li&gt;Your middleware reads &lt;code&gt;BR&lt;/code&gt; → maps to &lt;code&gt;pt&lt;/code&gt; → sets cookie&lt;/li&gt;
&lt;li&gt;Your app shows Portuguese content&lt;/li&gt;
&lt;li&gt;User switches to English via selector → cookie updates&lt;/li&gt;
&lt;li&gt;Next visit → reads cookie → remembers preference&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The Result
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Before&lt;/strong&gt;: Default language for everyone, manual selection required&lt;br&gt;&lt;br&gt;
&lt;strong&gt;After&lt;/strong&gt;: Automatic detection with smart fallbacks&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time invested&lt;/strong&gt;: ~5 minutes&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Lines of code&lt;/strong&gt;: ~100&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Complexity&lt;/strong&gt;: Minimal&lt;br&gt;&lt;br&gt;
&lt;strong&gt;User experience&lt;/strong&gt;: Significantly improved ✨&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;: Don't overthink it. Modern hosting platforms already give you geolocation for free. Just read the headers and map countries to languages. Done! 🎉&lt;/p&gt;

</description>
      <category>webdev</category>
    </item>
    <item>
      <title>expo hot reloading problem</title>
      <dc:creator>alyson farias</dc:creator>
      <pubDate>Sun, 26 Oct 2025 00:39:26 +0000</pubDate>
      <link>https://dev.to/nosylasairaf/expo-hot-reloading-problem-4d6a</link>
      <guid>https://dev.to/nosylasairaf/expo-hot-reloading-problem-4d6a</guid>
      <description>&lt;p&gt;you should use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx expo prebuild --clean
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx expo start --clear
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Como ler um artigo que saiu do ar usando a Wayback Machine</title>
      <dc:creator>alyson farias</dc:creator>
      <pubDate>Mon, 22 Sep 2025 14:48:57 +0000</pubDate>
      <link>https://dev.to/nosylasairaf/como-ler-um-artigo-que-saiu-do-ar-usando-a-wayback-machine-29i5</link>
      <guid>https://dev.to/nosylasairaf/como-ler-um-artigo-que-saiu-do-ar-usando-a-wayback-machine-29i5</guid>
      <description>&lt;p&gt;Você clica em um link em um vídeo no YouTube e dá de cara com o erro 404 – Página não encontrada. A página existiu, mas foi removida.&lt;/p&gt;

&lt;p&gt;Se o artigo vale a pena, ainda há saída: usar a Wayback Machine. O site mantém cópias antigas de páginas da web. Basta colar o link quebrado, escolher uma versão arquivada e acessar o conteúdo como se ainda estivesse online.&lt;/p&gt;

&lt;p&gt;(Vide Imagem abaixo)&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%2Fbdfx5zve6ek2p5grs57n.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%2Fbdfx5zve6ek2p5grs57n.png" alt=" " width="800" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Solução -&amp;gt;&lt;/p&gt;

&lt;p&gt;Wayback Machine &lt;a href="https://web.archive.org/" rel="noopener noreferrer"&gt;https://web.archive.org/&lt;/a&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%2Fxjyk0hcp7mkh95oatsu2.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%2Fxjyk0hcp7mkh95oatsu2.png" alt=" " width="800" height="525"&gt;&lt;/a&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%2Fayquyztn14kak93ugzqr.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%2Fayquyztn14kak93ugzqr.png" alt=" " width="800" height="251"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>how to deal with any ORM framework properly?</title>
      <dc:creator>alyson farias</dc:creator>
      <pubDate>Wed, 23 Jul 2025 12:17:50 +0000</pubDate>
      <link>https://dev.to/nosylasairaf/how-to-deal-with-any-orm-framework-properly-1a89</link>
      <guid>https://dev.to/nosylasairaf/how-to-deal-with-any-orm-framework-properly-1a89</guid>
      <description>&lt;p&gt;&lt;strong&gt;Understand the Abstraction&lt;/strong&gt;&lt;br&gt;
Learn how the ORM maps database tables to objects (Active Record vs. Data Mapper). Read its core concepts: model definition, relationships, querying, transactions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ignore Sugar Initially&lt;/strong&gt;&lt;br&gt;
Avoid shortcuts, decorators, and magic methods at first. Manually define fields, types, and constraints. Explicit over implicit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Control the Query Layer&lt;/strong&gt;&lt;br&gt;
Use logging or query inspection tools to view generated SQL. Validate against expectations. Know how to bypass ORM and run raw SQL when needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Handle Relationships Manually First&lt;/strong&gt;&lt;br&gt;
Define foreign keys and join conditions yourself before relying on association helpers. Understand cascading behavior and lazy vs. eager loading.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Batch and Lazy Load Intelligently&lt;/strong&gt;&lt;br&gt;
Profile and reduce N+1 queries. Know how to prefetch or batch load when needed. Learn the ORM's method for controlling load strategies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test with Real Data Shapes&lt;/strong&gt;&lt;br&gt;
Validate against edge cases, empty sets, nested relations, and massive rows. Check transaction behavior and rollback.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Avoid Over-Reliance on Migrations&lt;/strong&gt;&lt;br&gt;
Track schema changes directly. Know when to bypass migration tools and write SQL. ORM migration layers often lag or make dangerous assumptions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Handle Sessions/Connections Properly&lt;/strong&gt;&lt;br&gt;
Know how the ORM manages sessions, pools, and commits. Explicitly handle lifecycles in request/response or batch processing contexts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep Business Logic Outside Models&lt;/strong&gt;&lt;br&gt;
Treat models as data access layers. Encapsulate logic in service layers or domain logic, not inside ORM entity methods.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benchmark Before Shipping&lt;/strong&gt;&lt;br&gt;
Profile ORM performance vs. direct SQL for key paths. Optimize joins, subqueries, indexing. ORM adds overhead — know its cost.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Front-End Optimization: Debouncing and Throttling Explained In Short</title>
      <dc:creator>alyson farias</dc:creator>
      <pubDate>Sun, 04 Aug 2024 02:50:08 +0000</pubDate>
      <link>https://dev.to/nosylasairaf/front-end-optimization-debouncing-and-throttling-explained-in-short-15ah</link>
      <guid>https://dev.to/nosylasairaf/front-end-optimization-debouncing-and-throttling-explained-in-short-15ah</guid>
      <description>&lt;h2&gt;
  
  
  What is Debouncing?
&lt;/h2&gt;

&lt;p&gt;Debouncing is a technique that delays the execution of a function until the user stops performing a certain action for a specified amount of time.&lt;/p&gt;

&lt;p&gt;If you have a search bar that fetches suggestions from the backend as the user types, you can debounce the function that makes the API call, so that it only runs after the user stops typing for a few seconds. This way, you can avoid making too many API calls that might overload your server or return irrelevant results.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Throttling?
&lt;/h2&gt;

&lt;p&gt;Throttling is a technique that limits the execution of a function to once in every specified time interval.&lt;br&gt;
Common use:&lt;/p&gt;

&lt;p&gt;If you have a resize event handler that adjusts the layout of your page, you can throttle the function that updates the layout, so that it only runs once every 100ms. This way, you can avoid running your code too frequently, which might cause janky user interface or high CPU usage.&lt;/p&gt;

&lt;h5&gt;
  
  
  You can see clearly in this video
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://x.com/_ntnhon/status/1485718357995401224" rel="noopener noreferrer"&gt;Debounce vs Throttle&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reference: &lt;a href="https://medium.com/@bs903944/debounce-and-throttling-what-they-are-and-when-to-use-them-eadd272fe0be" rel="noopener noreferrer"&gt;Debounce vs Throttle&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>It is all about time to market</title>
      <dc:creator>alyson farias</dc:creator>
      <pubDate>Sat, 13 Jul 2024 19:50:44 +0000</pubDate>
      <link>https://dev.to/nosylasairaf/it-is-all-about-time-to-market-1hki</link>
      <guid>https://dev.to/nosylasairaf/it-is-all-about-time-to-market-1hki</guid>
      <description>&lt;h1&gt;
  
  
  It is all about time to market
&lt;/h1&gt;

&lt;p&gt;Recently, my sister became a mom, and motherhood comes with new problems that need solutions. Stay with me as I explain my point.&lt;/p&gt;

&lt;p&gt;She gave me a list of issues and suggested a website or app could solve them. We brainstormed ideas like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tracking diaper changes (pee/poop) to see if the baby's output is normal&lt;/li&gt;
&lt;li&gt;Daily, weekly, and monthly reports&lt;/li&gt;
&lt;li&gt;Counting feedings and which breast was used&lt;/li&gt;
&lt;li&gt;Tracking the baby's sleep duration&lt;/li&gt;
&lt;li&gt;Estimating diaper costs&lt;/li&gt;
&lt;li&gt;Medication reminders&lt;/li&gt;
&lt;li&gt;Recording the baby's temperature&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I then searched the Play Store and found a solution that's been around since 2015. This simple app solves her problems and costs only 12 reais (BRL) (~$2.1 USD) per year. It boasts over 1 million downloads and 100,000 reviews, with 95% of them positive. It likely requires minimal maintenance from the developer, who probably doesn't need a team.&lt;/p&gt;

&lt;p&gt;code is just commodity and&lt;br&gt;
&lt;a href="https://websim.ai/c/aKIsBIa3aaphyYaJB" rel="noopener noreferrer"&gt;sometimes, success is about being in the right place at the right time&lt;/a&gt; with the right knowledge to build.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FFp01TSOXwAEJILH%3Fformat%3Djpg%26name%3Dmedium" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FFp01TSOXwAEJILH%3Fformat%3Djpg%26name%3Dmedium" alt="looking out at a large, translucent crystal floating in the sky above a sea of clouds"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>key metrics to measure web perfomance; an short introduction</title>
      <dc:creator>alyson farias</dc:creator>
      <pubDate>Wed, 19 Jun 2024 22:01:26 +0000</pubDate>
      <link>https://dev.to/nosylasairaf/key-metrics-to-measure-web-perfomance-an-short-introduction-2dmp</link>
      <guid>https://dev.to/nosylasairaf/key-metrics-to-measure-web-perfomance-an-short-introduction-2dmp</guid>
      <description>&lt;p&gt;Monitoring web performance is crucial for ensuring optimal user experience and business success. Here some key metrics to consider:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. &lt;strong&gt;Page Load Time&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Page load time measures how long it takes for a web page to fully load in a user's browser. Faster load times improve user satisfaction and engagement.&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%2Fr1jk44ii3dgwt0e4p154.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%2Fr1jk44ii3dgwt0e4p154.png" alt="Image description" width="800" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;strong&gt;Time to First Byte (TTFB)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;TTFB measures the time taken by the browser to receive the first byte of response from the server after requesting a web page. It indicates server responsiveness.&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%2F8mjl3l28ilb3an0n0bmz.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%2F8mjl3l28ilb3an0n0bmz.png" alt="Image description" width="259" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Practical Example:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;When a user visits a website, their browser sends a request to the server to fetch the web page. The server processes this request, retrieves the necessary data (HTML, CSS, JavaScript, images, etc.), and starts sending it back to the browser. TTFB specifically measures the time it takes from the moment the browser sends the request until it receives the first byte of data from the server.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For instance, if a user accesses a news website, the TTFB can vary depending on server load and network conditions. A fast TTFB (e.g., under 200 milliseconds) means the server responds quickly, delivering the initial content promptly. A slow TTFB (e.g., over 1 second) indicates potential issues with server performance or network latency, leading to longer wait times for users.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. &lt;strong&gt;First Contentful Paint (FCP)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;FCP measures the time when the browser first renders any content on the screen, such as text, images, or non-white canvas. It gives a sense of when the user perceives the page as loading.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. &lt;strong&gt;Time to Interactive (TTI)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;TTI measures when the page is fully interactive and responsive to user input. It's crucial for determining when users can start engaging with the content.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. &lt;strong&gt;Total Blocking Time (TBT)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;TBT measures the total amount of time between First Contentful Paint and Time to Interactive when the main thread is blocked and unable to respond to user input.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. &lt;strong&gt;Load Distribution&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Load distribution metrics assess how resources (like images, scripts, and stylesheets) are distributed across different servers or Content Delivery Networks (CDNs) to optimize load times.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. &lt;strong&gt;Error Rate&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Error rate tracks the percentage of requests that result in errors, such as 404 (not found) or 500 (server error). High error rates can indicate issues with server configurations or network problems.&lt;/p&gt;

&lt;p&gt;All this metrics influence influence conversion rate as we are human &lt;/p&gt;

&lt;p&gt;You can measure so many things using the performance API&lt;br&gt;
&lt;code&gt;const resources = performance.getEntriesByType("resource");&lt;br&gt;
        const paints = performance.getEntriesByType("paint");&lt;br&gt;
        const navigations=performance.getEntriesByType("navigation");&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;useful&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Performance" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/API/Performance&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://pagespeed.web.dev/" rel="noopener noreferrer"&gt;https://pagespeed.web.dev/&lt;/a&gt; &lt;/p&gt;

</description>
    </item>
    <item>
      <title>a web perfomance introduction and why you should care;</title>
      <dc:creator>alyson farias</dc:creator>
      <pubDate>Wed, 19 Jun 2024 21:21:47 +0000</pubDate>
      <link>https://dev.to/nosylasairaf/web-perfomance-and-why-you-should-care-4n8j</link>
      <guid>https://dev.to/nosylasairaf/web-perfomance-and-why-you-should-care-4n8j</guid>
      <description>&lt;p&gt;Improving the performance of your website/web product impacts several critical metrics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User Satisfaction and Retention&lt;/li&gt;
&lt;li&gt;Cost Savings&lt;/li&gt;
&lt;li&gt;Competitive Advantage&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/search/blog/2018/01/using-page-speed-in-mobile-search" rel="noopener noreferrer"&gt;Improved SEO&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;High Conversion Rate&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before diving in, let's define two key metrics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Bounce Rate:&lt;/strong&gt; Percentage of visitors who leave your website after viewing only one page, indicating engagement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conversion Rate:&lt;/strong&gt; Measures how effectively your site turns visitors into customers or leads.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Impact of Page Load Time
&lt;/h2&gt;

&lt;p&gt;As page load time increases, so does the bounce rate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Increasing load time from 1 to 3 seconds raises bounce probability by 32% &lt;/li&gt;
&lt;li&gt;Deloitte found that a jump from 1 to 5 seconds increases bounce probability by 90%.&lt;/li&gt;
&lt;li&gt;A 10-second load time increases bounce probability by 123%.
&lt;em&gt;(Google/SOASTA, 2017).&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Financial Implications
&lt;/h2&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;eBay's 100-millisecond speed improvement increased add-to-cart rates by 0.5%, leading to 50,000 more monthly transactions.&lt;/li&gt;
&lt;li&gt;BMW's adoption of Progressive Web Apps (PWA) boosted traffic by 8 to 40%.
&lt;em&gt;(Milliseconds Make Million from Deloitte)&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Strategies for Improvement
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Improving Conversion Rate:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Optimize User Experience: Simplify the user journey.&lt;/li&gt;
&lt;li&gt;Enhance Content Quality: Ensure relevance and persuasion.&lt;/li&gt;
&lt;li&gt;A/B Testing: Experiment with different versions for better performance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Reducing Bounce Rate:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Improve Page Load Speed: Ensure fast loading times.&lt;/li&gt;
&lt;li&gt;Enhance Content Relevance: Align content with visitor intent.&lt;/li&gt;
&lt;li&gt;Engage with Design: Create an intuitive and attractive layout.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;if you are a web developer and need to know little more about &lt;a href="https://dev.to/nosylasairaf/key-metrics-to-measure-web-perfomance-an-short-introduction-2dmp"&gt;key metrics to measure web perfomance&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>perfomance</category>
      <category>programming</category>
      <category>webperfomance</category>
    </item>
    <item>
      <title>Você talvez não saiba tratar erros usando Fetch API corretamente</title>
      <dc:creator>alyson farias</dc:creator>
      <pubDate>Tue, 12 Dec 2023 12:32:25 +0000</pubDate>
      <link>https://dev.to/nosylasairaf/voce-talvez-nao-saiba-tratar-erros-usando-fetch-api-corretamente-21in</link>
      <guid>https://dev.to/nosylasairaf/voce-talvez-nao-saiba-tratar-erros-usando-fetch-api-corretamente-21in</guid>
      <description>&lt;p&gt;O Fetch API não é tão novo, e a maioria dos desenvolvedores já o utilizou em algum momento para obter recursos de um servidor. No entanto, será que você realmente sabe como lidar com erros ao usar essa API?&lt;/p&gt;

&lt;p&gt;Dado o código abaixo, em que uma solicitação usando a Fetch API retorna um erro 404, qual seria a mensagem no console: &lt;strong&gt;sucesso&lt;/strong&gt; ou &lt;strong&gt;falhou&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;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// este endpoint retornará 404&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://restcountries.com/v4.1/all&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="s1"&gt;Sucesso&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;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;Falhou&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;Se você assumir que este código registra a mensagem de falha quando ocorre um erro 404, eu diria que este artigo é definitivamente para você, porque sua resposta está incorreta. O console.log exibirá a mensagem &lt;strong&gt;sucesso&lt;/strong&gt;, e vou explicar por quê e qual é a melhor maneira de lidar com erros usando a Fetch API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;O que é a Fetch API?&lt;/strong&gt;&lt;br&gt;
Em resumo, a Fetch API é uma interface para fazer facilmente solicitações HTTP assíncronas do tipo GET e POST para endpoints.&lt;/p&gt;

&lt;p&gt;Como lidar com erros usando a Fetch API?&lt;br&gt;
Ao usar a Fetch API, diferentes erros podem ocorrer, como: erro do servidor (500), erro não encontrado (404), erro de rede, erro CORS, entre outros. E temos abordagens diferentes para lidar com todos esses erros, como você verá abaixo.&lt;/p&gt;

&lt;p&gt;Usando try/catch para lidar com erros da Fetch API:&lt;br&gt;
Estou presumindo que você está familiarizado com promisses em JavaScript e sabe como elas funcionam (porque uma das razões pelas quais a Fetch API é tão popular é porque ela retorna uma promisse). Portanto, podemos usar o poder de then, catch e finally quando a fetch é resolvida, rejeitada e concluída.&lt;/p&gt;

&lt;p&gt;Envolvendo a chamada fetch em um bloco try/catch é uma maneira muito comum de lidar com erros (veja o exemplo abaixo), mas nem todos os erros podem ser capturados, e explicarei isso logo após o código.&lt;/p&gt;

&lt;p&gt;javascript&lt;br&gt;
Copy code&lt;br&gt;
try {&lt;br&gt;
  // este endpoint retornará um erro CORS&lt;br&gt;
  const response = await fetch('&lt;a href="https://google.com/api'" rel="noopener noreferrer"&gt;https://google.com/api'&lt;/a&gt;);&lt;br&gt;
} catch {&lt;br&gt;
  console.error('Falhou');&lt;br&gt;
}&lt;br&gt;
// Saída: Falhou&lt;br&gt;
Este código tentará realizar uma busca e detectar erros apenas quando a promisse for rejeitada (o que pode ocorrer em dois cenários):&lt;/p&gt;

&lt;p&gt;Erros de rede: falha ao conectar-se ao servidor, o que pode ser causado por vários motivos, como rede lenta e tempo limite, por exemplo.&lt;br&gt;
Erros CORS: quando um domínio não está autorizado a obter recursos de um domínio diferente.&lt;br&gt;
A Fetch retornará resolvido para erros de status do servidor (como 404 e 500, por exemplo), e é por isso que o catch não pode capturá-los no exemplo no início deste artigo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verificando o status da resposta para lidar com erros da Fetch API:&lt;/strong&gt;&lt;br&gt;
Outra maneira comum de lidar com erros usando a Fetch API é verificar o status da resposta quando a promisse é resolvida - e é assim que devemos obter o erro 404 no exemplo no início deste artigo:&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;// este endpoint retornará 404&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://restcountries.com/v4.1/all&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// ...faça algo com a resposta se response.ok for verdadeiro&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;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;Falhou&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Aqui, usamos response.ok para verificar se a resposta foi bem-sucedida ou não (verdadeiro ou falso).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;É verdadeiro quando o código de status está entre 200 e 299 (significa bem-sucedido).&lt;br&gt;
É falso quando o servidor retorna qualquer outro status que não esteja acima. Exemplos são 404 (não encontrado) e 500 (erro interno do servidor).&lt;br&gt;
Melhor maneira de lidar com erros usando a Fetch API:&lt;br&gt;
&lt;strong&gt;Exemplo 01:&lt;/strong&gt;&lt;br&gt;
Como você viu acima, try/catch e response.ok são usados para capturar diferentes tipos de erros, então podemos combinar as duas abordagens para lidar melhor com erros usando a Fetch API. Veja o exemplo abaixo:&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;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://restcountries.com/v4.1/all&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&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;promisse resolvida e status HTTP é bem-sucedido&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// ...faça algo com a resposta&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;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;promisse resolvida, mas status HTTP falhou&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="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;promisse rejeitada&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explicação:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;try/catch é usado para obter erros quando a promisse é rejeitada (problemas de rede ou CORS).&lt;br&gt;
response.ok é usado para lidar com erros do servidor (404 ou 500, por exemplo) quando a promisse é resolvida.&lt;br&gt;
&lt;strong&gt;Exemplo 02:&lt;/strong&gt;&lt;br&gt;
 Outra maneira comum de lidar com erros dentro do bloco try é lançar um erro quando response.ok não é verdadeiro, para que o bloco catch seja executado e possamos lidar com todos os erros no mesmo lugar. Veja o exemplo abaixo para entender melhor:&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;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://restcountries.com/v4.1/all&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&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;promisse resolvida e status HTTP é bem-sucedido&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// ...faça algo com a resposta&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="c1"&gt;// Mensagem personalizada para códigos HTTP falhados&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;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&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;404, Não encontrado&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&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;500, erro interno do servidor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// Para qualquer outro erro do servidor&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Fetch&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="c1"&gt;// Saída por exemplo: "Erro no Fetch: 404, Não encontrado"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>frontend</category>
      <category>programacao</category>
      <category>desenvolvimentoweb</category>
    </item>
    <item>
      <title>Identifique e apague todas node_modules com NP Kill</title>
      <dc:creator>alyson farias</dc:creator>
      <pubDate>Tue, 02 Aug 2022 02:06:00 +0000</pubDate>
      <link>https://dev.to/nosylasairaf/identifique-e-apague-todas-nodemodules-com-npm-kill-bpj</link>
      <guid>https://dev.to/nosylasairaf/identifique-e-apague-todas-nodemodules-com-npm-kill-bpj</guid>
      <description>&lt;p&gt;Eu sei, você trabalha com Javascript, e precisa de instalar variadas dependências. &lt;br&gt;
  O problema é que com o passar do tempo você se depara com vários projetos consumindo sua memória sem necessidade, pois precisamos do projeto vez ou outra, mas não do node_modules(a pasta mais pesada) necessariamente. &lt;/p&gt;

&lt;p&gt;O Npkill faz uma varredura em todo computador identificando as pastas node_modules e possibilita a exclusão ao pressionar [SPACE] &lt;br&gt;
via CLI.&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%2Fdo0l06p6fd6823cjw752.gif" 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%2Fdo0l06p6fd6823cjw752.gif" alt="Image description" width="793" height="367"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Instalação
&lt;/h3&gt;

&lt;p&gt;Você não precisa necessariamente instalar, pode simplesmente usar o comando abaixo&lt;br&gt;
&lt;code&gt;npx kill&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Ou caso quiser instalar&lt;br&gt;
&lt;code&gt;npm i -g npkill&lt;br&gt;
 #caso use Linux talvez precise utilizar sudo, cuidado.&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Logo após &lt;br&gt;
&lt;code&gt;npkill&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Referência:&lt;br&gt;
&lt;a href="https://www.npmjs.com/package/npkill" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/npkill&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
