<?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: Devesh Anand Srivastava</title>
    <description>The latest articles on DEV Community by Devesh Anand Srivastava (@deveshanand18).</description>
    <link>https://dev.to/deveshanand18</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%2F582698%2Fac0f9f18-77e4-4043-9c1f-4691bc1ce8ee.jpg</url>
      <title>DEV Community: Devesh Anand Srivastava</title>
      <link>https://dev.to/deveshanand18</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/deveshanand18"/>
    <language>en</language>
    <item>
      <title>Next.js 13 is here</title>
      <dc:creator>Devesh Anand Srivastava</dc:creator>
      <pubDate>Sun, 06 Nov 2022 18:03:23 +0000</pubDate>
      <link>https://dev.to/deveshanand18/nextjs-13-is-here-5f5p</link>
      <guid>https://dev.to/deveshanand18/nextjs-13-is-here-5f5p</guid>
      <description>&lt;p&gt;Next.js 13 was announced recently at &lt;a href="https://nextjs.org/conf" rel="noopener noreferrer"&gt;Next conf&lt;/a&gt; with plethora of new (and evolved) features that will make the process of writing and maintaining frontend code for software companies (and devs) like ours (&lt;a href="https://www.itmtb.com/" rel="noopener noreferrer"&gt;itmtb.com&lt;/a&gt;) easier by improving quality, efficiency and readability of code.&lt;/p&gt;

&lt;p&gt;Some of those features:&lt;/p&gt;

&lt;h2&gt;
  
  
  Server-side components by default:
&lt;/h2&gt;

&lt;p&gt;Remember using &lt;code&gt;getStaticProps&lt;/code&gt;, &lt;code&gt;getStaticPaths&lt;/code&gt; and &lt;code&gt;getServerSideProps&lt;/code&gt;? Well, they'll be obsolete in Next 13. Now is this a good step? In most cases, yes. Take the simple code below for example:&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%2Ftl5ui1wkn426r0625b4f.jpg" 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%2Ftl5ui1wkn426r0625b4f.jpg" alt="Server side prop in Next &amp;lt;=12 vs Next 13" width="800" height="289"&gt;&lt;/a&gt;&lt;br&gt;Server side prop in Next &amp;lt;=12 vs Next 13
  &lt;/p&gt;

&lt;p&gt;Apart from making the code more readable, server-side components bring in other advantages, like reducing client-side JavaScript bundle.&lt;/p&gt;

&lt;p&gt;In large production apps with a lot of dependencies, it becomes a painful challenge for developers to reduce the bundle size, that too without compromising on functionalities. With server-side components, a major portion of dependencies never reach client-side, reducing the bundle size drastically.&lt;/p&gt;

&lt;p&gt;Client-side components still have their purpose though, and any component can be made client side by simply adding &lt;code&gt;'use client'&lt;/code&gt; as the very first line. Whenever you need to re-render, or use &lt;code&gt;useEffect&lt;/code&gt; you can easily make the component client-side.&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%2F0d9lwky28nk6scoewyso.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%2F0d9lwky28nk6scoewyso.png" alt="Client-side component in Next 13" width="800" height="851"&gt;&lt;/a&gt;&lt;br&gt;Client-side component in Next 13
  &lt;/p&gt;

&lt;h2&gt;
  
  
  An awesome layout system:
&lt;/h2&gt;

&lt;p&gt;Next.js 13 introduces a new layout system at route level. &lt;/p&gt;

&lt;p&gt;For example, we can now have custom layout for all pages in &lt;code&gt;/blog&lt;/code&gt; route. Just put the layout in &lt;code&gt;layput.{js/jsx/ts/tsx}&lt;/code&gt; under &lt;code&gt;blog&lt;/code&gt; folder in &lt;code&gt;pages&lt;/code&gt; (or &lt;code&gt;app&lt;/code&gt; in Next.13) directory.&lt;/p&gt;

&lt;p&gt;You can even have custom error component, or loading component based on routes. This definitely makes the developer experience way better and easier. Layouts even preserve state and don't re-render.&lt;/p&gt;

&lt;p&gt;A deeper explanation of layout in Next 13:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/6mQ3M1CUGnk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Turbopack:
&lt;/h2&gt;

&lt;p&gt;Let's be honest, &lt;a href="https://webpack.js.org/" rel="noopener noreferrer"&gt;webpack&lt;/a&gt; has been an essential part of the web, but with time it has shown it's drawbacks. It has it's fair share of non-fixable &lt;a href="https://medium.com/hurb-labs/the-problem-with-webpack-8a025268a761" rel="noopener noreferrer"&gt;issues&lt;/a&gt; and it has hit the cap for performance for a bundler written in JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://vercel.com/blog/turbopack" rel="noopener noreferrer"&gt;Turbopack&lt;/a&gt;, a bundler written in Rust claims to solve the issue. As per Vercel's claims, it does:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;700x faster updates than Webpack&lt;/li&gt;
&lt;li&gt;10x faster updates than Vite&lt;/li&gt;
&lt;li&gt;4x faster cold starts than Webpack&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The benchmarks are a topic of debate themselves, like the ones claiming Turbopack being 10x faster than &lt;a href="https://vitejs.dev/" rel="noopener noreferrer"&gt;Vite&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1586317587348017152-272" src="https://platform.twitter.com/embed/Tweet.html?id=1586317587348017152"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1586317587348017152-272');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1586317587348017152&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;Nonetheless, it is faster than Vite (way faster than webpack) and shows a lot of promise.&lt;/p&gt;

&lt;h2&gt;
  
  
  Image and Font:
&lt;/h2&gt;

&lt;p&gt;Next.js 13 has a better &lt;code&gt;next/image&lt;/code&gt; since it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is faster as it ships less JavaScipt to client-side and doesn't need hydration.&lt;/li&gt;
&lt;li&gt;Requires &lt;code&gt;alt&lt;/code&gt; tag by default for better accessibility.&lt;/li&gt;
&lt;li&gt;Easier to style.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next.js 13 also introduces a &lt;a href="https://nextjs.org/blog/next-13#nextfont" rel="noopener noreferrer"&gt;font-system&lt;/a&gt; through which you can use any Google font, &lt;em&gt;without sending request&lt;/em&gt; to Google from browser. Fonts are downloaded at build time and self-hosted in your project. This improves both privacy and performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  SEO:
&lt;/h2&gt;

&lt;p&gt;When sharing a blog-post or a page of website, you would've noticed a card like the one below:&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%2Fttoeeafp4cc5cmroqsqn.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%2Fttoeeafp4cc5cmroqsqn.png" alt="Social card for SEO" width="596" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This card is produced using &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tags in &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; section of page. The image is produced using&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;&amp;lt;meta property="og:image" content="img_url/path" /&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
. Vercel has created a new library, &lt;code&gt;@vercel/og&lt;/code&gt;, that works with Next.js 13 to create dynamic social cards.&lt;/p&gt;

&lt;p&gt;You can explicitly create profile cards using &lt;code&gt;@vercel/og&lt;/code&gt; like 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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ImageResponse&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@vercel/og&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;runtime&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;experimental-edge&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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handler&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="nc"&gt;ImageResponse&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;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;
        &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;
          &lt;span class="na"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#fff&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;backgroundImage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;radial-gradient(circle at 25px 25px, lightgray 2%, transparent 0%), radial-gradient(circle at 75px 75px, lightgray 2%, transparent 0%)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;backgroundSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;100px 100px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;100%&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;100%&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;textAlign&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;center&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;alignContent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;center&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;alignItems&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;center&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;justifyContent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;center&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;flexDirection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;column&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;flex&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;img&lt;/span&gt;
          &lt;span class="nx"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Vercel&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
          &lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;225&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTE2IiBoZWlnaHQ9IjEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTU3LjUgMEwxMTUgMTAwSDBMNTcuNSAweiIgLz48L3N2Zz4=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0 75px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
        &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;
          &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;
            &lt;span class="na"&gt;fontSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;marginTop&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;lineHeight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.8&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="nx"&gt;Vercel&lt;/span&gt; &lt;span class="nx"&gt;Edge&lt;/span&gt; &lt;span class="nx"&gt;Network&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code provides us with the card below for &lt;a href="https://vercel-og-nextjs-one-phi.vercel.app/" rel="noopener noreferrer"&gt;this url&lt;/a&gt;. &lt;br&gt;
(&lt;a href="https://github.com/devesh-anand/vercel-og-nextjs" rel="noopener noreferrer"&gt;Full code for the Next project&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%2F0m1aj0nv9qyulacsmpv7.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%2F0m1aj0nv9qyulacsmpv7.png" alt="Custom generated profile card" width="553" height="370"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Backend updates:
&lt;/h2&gt;

&lt;p&gt;Next.js being a full-stack framework, has brought some backend changes as well:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Middlewares&lt;/li&gt;
&lt;li&gt;You can now use middleware to handle &lt;code&gt;rewrite&lt;/code&gt; and &lt;code&gt;redirect&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Final thoughts:
&lt;/h3&gt;

&lt;p&gt;Some of the features (like &lt;code&gt;next/font&lt;/code&gt;) are still in beta and might take some time before they're production ready. Also, migration might not be that easy, considering the major changes happening in Next.js 13. &lt;/p&gt;

&lt;p&gt;Although Next has provided a &lt;a href="https://beta.nextjs.org/docs/upgrade-guide" rel="noopener noreferrer"&gt;migration guide from v12 to v13&lt;/a&gt;, it might still be tricky to migrate from older versions.&lt;/p&gt;

&lt;p&gt;But for new projects, Next.js 13 seems promising. It will be better in almost all aspects, be it user-experience, developer-experience or maintenance, for both developers and companies.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>nextjs</category>
      <category>jamstack</category>
    </item>
    <item>
      <title>How Computers generate random numbers ?</title>
      <dc:creator>Devesh Anand Srivastava</dc:creator>
      <pubDate>Tue, 18 May 2021 16:16:26 +0000</pubDate>
      <link>https://dev.to/deveshanand18/how-computers-generate-random-numbers-3il</link>
      <guid>https://dev.to/deveshanand18/how-computers-generate-random-numbers-3il</guid>
      <description>&lt;p&gt;We have all used &lt;code&gt;.random()&lt;/code&gt; function in our programming journey, which returned us some random number in some specified range. Did you ever think how the random number was generated?&lt;/p&gt;

&lt;p&gt;You'll agree that, &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"A computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations automatically."&lt;br&gt;
  - &lt;em&gt;&lt;a href="https://en.wikipedia.org/wiki/Computer" rel="noopener noreferrer"&gt;Wikipedia&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then how can a computer be programmed to generate a random number through sequence of operations? If some random number is generated through some sequence of steps (algorithm), is it truly random? This takes us to the types of random numbers there are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;True Random Numbers&lt;/li&gt;
&lt;li&gt;Pseudo Random Numbers&lt;/li&gt;
&lt;/ol&gt;




&lt;h1&gt;
  
  
  1. True Random Numbers:
&lt;/h1&gt;

&lt;p&gt;As the name suggests, they are truly random. Since an algorithmically generated number can't be a random number in true sense, true random numbers are generated using unpredictable data from real world, like the rpm (rotations per minute) of CPU fan, or exact time you press a key on your keyboard, or atmospheric noise around the computer. Such physical phenomenon give completely unpredictable set of entropy (randomness), making true random numbers secure. &lt;/p&gt;

&lt;p&gt;Random number generators of this kind are called True random number generators (TRNGs). Linux uses &lt;a href="https://en.wikipedia.org/wiki//dev/random" rel="noopener noreferrer"&gt;dev/random&lt;/a&gt; to collect &lt;em&gt;entropy&lt;/em&gt; from atmosphere around you, and creates true random numbers. It gathers &lt;em&gt;entropy&lt;/em&gt; in form of environmental noise through device drivers.&lt;/p&gt;




&lt;h1&gt;
  
  
  2. Pseudo Random Numbers:
&lt;/h1&gt;

&lt;p&gt;These are alternative to true random numbers, generated using some seed value and some algorithm. The numbers generated seem to be random, but are predictable in reality if seed value and algorithm is known.&lt;/p&gt;

&lt;p&gt;As you might have already guessed, they are not great from security perspective. This is why using PRNGs in encryption is a bad idea. FreeBSD takes it &lt;a href="https://arstechnica.com/information-technology/2013/12/we-cannot-trust-intel-and-vias-chip-based-crypto-freebsd-developers-say/" rel="noopener noreferrer"&gt;rather seriously&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Random number generators generating these kinds of numbers are called pseudo random number generators (PRNGs). PRNGs are faster compared to TRNGs, and are useful in scenarios where security is not a concern, like games, or while learning programming.&lt;/p&gt;




&lt;p&gt;One of the most common PRNG is &lt;a href="https://en.wikipedia.org/wiki/Linear_congruential_generator" rel="noopener noreferrer"&gt;linear congruential generator&lt;/a&gt;. Let's see how it works.&lt;/p&gt;

&lt;p&gt;It uses recurrence:&lt;/p&gt;

&lt;p&gt;Xn+1 = (aXn + b) mod m&lt;/p&gt;

&lt;p&gt;Where,&lt;br&gt;
X is sequence of pseudo random values&lt;br&gt;
m is the modulus&lt;br&gt;
a the multiplier&lt;br&gt;
c the increment&lt;br&gt;
X0 the seed value&lt;/p&gt;

&lt;p&gt;Let's have an example. Taking X0 as 10,&lt;br&gt;
a = 22,&lt;br&gt;
c = 723,&lt;br&gt;
m = 10,000&lt;/p&gt;

&lt;p&gt;X1 = (aX0 + c) mod m&lt;br&gt;
X1 = ( 22(10) + 723 )mod 10000&lt;br&gt;
X1 = 943&lt;/p&gt;

&lt;p&gt;Now to get another random number X2, put value of X1 from above,&lt;/p&gt;

&lt;p&gt;X2 = (aX1 + c) mod m&lt;br&gt;
X2 = ( 22(943) + 743 )mod 10000&lt;br&gt;
X2 = 1489&lt;/p&gt;

&lt;p&gt;This is one of the numerous ways how you can generate different (pseudo) random numbers of different sizes.&lt;/p&gt;



&lt;p&gt;Javascript &lt;a href="https://www.geeksforgeeks.org/linear-congruence-method-for-generating-pseudo-random-numbers/" rel="noopener noreferrer"&gt;code&lt;/a&gt; for Linear Congruence method:&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;// Function to generate random numbers&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;linearCongruentialMethod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Xo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                     &lt;span class="nx"&gt;randomNums&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;noOfRandomNums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// Initialize the seed state&lt;/span&gt;
    &lt;span class="nx"&gt;randomNums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Xo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Traverse to generate required&lt;/span&gt;
    &lt;span class="c1"&gt;// numbers of random numbers&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;1&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="nx"&gt;noOfRandomNums&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="c1"&gt;// Follow the linear congruential method&lt;/span&gt;
        &lt;span class="nx"&gt;randomNums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;randomNums&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="nx"&gt;m&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="c1"&gt;// Driver Code&lt;/span&gt;

    &lt;span class="c1"&gt;// Seed value&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;Xo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
    &lt;span class="c1"&gt;// Modulus parameter&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// Multiplier term&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="c1"&gt;// Increment term&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="c1"&gt;// Number of Random numbers&lt;/span&gt;
    &lt;span class="c1"&gt;// to be generated&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;noOfRandomNums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// To store random numbers&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;randomNums&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;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;noOfRandomNums&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Function Call&lt;/span&gt;
    &lt;span class="nf"&gt;linearCongruentialMethod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Xo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                             &lt;span class="nx"&gt;randomNums&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                             &lt;span class="nx"&gt;noOfRandomNums&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="nx"&gt;noOfRandomNums&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomNums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &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="nl"&gt;Credits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Geeksforgeeks&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>computerscience</category>
      <category>cryptography</category>
      <category>algorithms</category>
    </item>
  </channel>
</rss>
