<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nadav Gabay on Medium]]></title>
        <description><![CDATA[Stories by Nadav Gabay on Medium]]></description>
        <link>https://medium.com/@nadavgabay?source=rss-5623ebb57381------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*yStq4kkTrhhkjta3.</url>
            <title>Stories by Nadav Gabay on Medium</title>
            <link>https://medium.com/@nadavgabay?source=rss-5623ebb57381------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 12:37:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nadavgabay/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Improve Exchange Application Performance using Next.JS]]></title>
            <link>https://medium.com/@nadavgabay/improve-exchange-application-performance-using-next-js-aa27d9f01a23?source=rss-5623ebb57381------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa27d9f01a23</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[education]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Nadav Gabay]]></dc:creator>
            <pubDate>Tue, 02 Nov 2021 13:29:20 GMT</pubDate>
            <atom:updated>2021-11-02T13:29:20.896Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RyadIG30l8OctkLp" /><figcaption>Photo by <a href="https://unsplash.com/@glenwheeler?utm_source=medium&amp;utm_medium=referral">Glen Wheeler</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Ever since I can remember, I have always loved speed. I loved to watch car racing, loved to do extreme sports, loved it when I no longer needed to wait for a music file of 4MB to be downloaded in 6 hours (the happy 90’s 🤩 ).</p><p>These days the passion for speed has become very common especially for “Gen Z”- everything needs to be immediate and fast.</p><blockquote>“IBM found<strong> 62% won’t use</strong> apps or websites that are difficult to navigate and 60% won’t use them if they’re slow to load” (Daphne Howland, <a href="https://www.retaildive.com/news/gen-z-twice-as-likely-to-convert-on-mobile/447867/">retaildive.com</a>)</blockquote><p>Recently, our <a href="https://www.inx.co/">INX Cryptocurrency Exchange</a> went live for the first time and we were very excited to see traders using it. However, very quickly we saw customers complaining about the performance of the site.</p><p>As a speed lover, I seized the mission and with a few steps we were able to reduce the bundle size by <strong>more than half</strong>, minimize the First Contentful Paint (FCP) to <strong>~0.7 sec, </strong>reduce the Memory Footprint <strong>from ~220MB to ~130MB </strong>and give the customers a smoother trading platform. 😎</p><h3>How did we manage to improve the performance?</h3><p>We can split it to two main changes:</p><ol><li>Shrink bundle size</li><li>Improve performance</li></ol><blockquote><strong>Note</strong>: Changes that you are making on the bundle size can also improve the performance of the site.</blockquote><h3><strong>JS bundle optimization</strong></h3><ol><li><strong>Run and analyze Google Lighthouse:<br></strong>To decrease it, the first thing that we did was to run <strong>Google Lighthouse</strong>. Google Lighthouse is a tool that provides powerful insights to help improve your website.<br>After you run it, you get a report that contains metrics and scores for each one of the insights. <br>Also it gives you suggestions of how you can improve each metric.</li></ol><figure><img alt="Google lighthouse example" src="https://cdn-images-1.medium.com/max/939/1*wz1LwJS19H9mT5LmdCdQqg.png" /><figcaption><a href="https://developers.google.com/web/tools/lighthouse">Google Lighthouse</a> report</figcaption></figure><p><strong>2. Analyze the Webpack Bundle:<br></strong>We used <a href="https://www.npmjs.com/package/webpack-bundle-analyzer">webpack-bundle-analyzer</a> to show us the biggest libraries we were using.</p><figure><img alt="webpack bundle analyzer illustration" src="https://cdn-images-1.medium.com/max/908/0*YZ3ayQoJgHtKpZYZ.gif" /><figcaption><a href="https://www.npmjs.com/package/webpack-bundle-analyzer">webpack bundle analyzer</a> demonstration</figcaption></figure><p>We saw that there were some improvements we can easily make here:</p><ul><li>Remove unused packages</li><li>Remove moment locales</li><li>Optimize Lodash imports</li></ul><p><strong>3. CSS Optimization:<br></strong>When we started to work on the INX cryptocurrency trading platform, we used both <a href="https://styled-components.com/">Styled-Components</a> to customize components CSS and <a href="https://lesscss.org/">Less</a> to customize general size CSS in the app.<br>Although I really believe in this arrangement- <a href="https://nextjs.org/">Next.js</a> doesn’t. <br>Since Next.js 9.5.4, Vercel team added a build to support<a href="https://github.com/css-modules/css-modules"> CSS-Modules</a> that split the CSS into <strong>many minified</strong> and <strong>code-split</strong> .css files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/601de49bec536d38c7f84e4893030ee9/href">https://medium.com/media/601de49bec536d38c7f84e4893030ee9/href</a></iframe><p>This change to CSS-Modules improved both the site performance and the bundle size.</p><p>How did it improve them? The post CSS parser goes over the code and automatically creates CSS chunks that ensure that the minimal amount of CSS is loaded for your application to paint.</p><p><strong>4. Images and Icons Optimization:</strong></p><ul><li>Icon files changed from PNG/JPG to SVG</li><li>All images in the site were published to a CDN and added as background-image url using CDN to show images</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65cae4601ad983fb4815d8872c3a00a5/href">https://medium.com/media/65cae4601ad983fb4815d8872c3a00a5/href</a></iframe><h3>Improve performance</h3><p><strong>5. Refactor code to use React hooks instead of class components:</strong></p><p>I think there is no need to expand on that too much.<br>Since React 16.8 Facebook added a new way to create “smart” and “thin” components instead of the classic “Class Components”.<br>For those who aren’t familiar with React hooks, I suggest you read <a href="https://betterprogramming.pub/react-hooks-vs-classes-add2676a32f2">this article</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83c51e85697aa296211927f7722925c3/href">https://medium.com/media/83c51e85697aa296211927f7722925c3/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74f2510667872d63fb5358f6b088c19e/href">https://medium.com/media/74f2510667872d63fb5358f6b088c19e/href</a></iframe><p><strong>6. Remove inline functions:<br></strong>Inline function is a function that is defined inside the “render” method of a component (“return” function when we talk about Functional Component). When you create a function inside the return function it hurts performance because the function is recreated in each render of the component, which means that every time the component re-renders, it first garbage collects the old function and then creates the new one — this operation takes time so it’s better to avoid it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b65025d09aa9727244acd45171f89cbf/href">https://medium.com/media/b65025d09aa9727244acd45171f89cbf/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc8286d06978b0ba2a142634f10fad4b/href">https://medium.com/media/cc8286d06978b0ba2a142634f10fad4b/href</a></iframe><p>7. <strong>Use Next dynamic import:<br></strong>When you are using a module bundler like Webpack it will create a bundle file that can be served easily from a server, but when your application is getting bigger the bundle file can get bigger and bigger and it will affect the <strong>site’s performance</strong> making your site load slowly.</p><p>In order to solve it, the modern module bundlers gave us an amazing option (that already came built-in with Next.js) called <strong>Code Splitting</strong>.</p><p>When Code Splitting is activated, the bundler splits the bundle file into small chunks.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FXcFqv8EzBiAlzeEID9%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Frickandmorty-season-3-adult-swim-rick-and-morty-XcFqv8EzBiAlzeEID9&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2FXcFqv8EzBiAlzeEID9%2Fgiphy.gif%3Fcid%3D790b7611e89d5ac6fff2db9e81578223e849f87f0b2a571f%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/54e3967fd1825bff03cabe9a72de0482/href">https://medium.com/media/54e3967fd1825bff03cabe9a72de0482/href</a></iframe><p>Next.js allows you to use dynamic import, so the import component will load the package/other component in a dynamic way. That way you can “lazy-load” only the things that are currently needed by the user which can dramatically improve the performance of your app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5a87585ba79579f84914d43266280f6/href">https://medium.com/media/b5a87585ba79579f84914d43266280f6/href</a></iframe><p><strong>8. Use Static Generation:</strong></p><p>Next.js gives us 3 methods to build the project:<br><strong>1. Client-side rendering</strong>- Content from the browser is rendered using Javascript.<br><strong>2. Server-side rendering</strong>- The HTML is generated on <strong>each request</strong><br><strong>3. Static Generation</strong>- The HTML is generated at <strong>build time</strong> and will be reused on each request</p><p>Each one of the methods has it’s pros and cons, but in general the Next.js team recommend using Static Generation (if you can) for better performance. The main reason is that you can take the output of the build process and cache them inside a CDN with no extra configuration.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F6ElI2ZJ4Uro%3Fstart%3D204%26feature%3Doembed%26start%3D204&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D6ElI2ZJ4Uro&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F6ElI2ZJ4Uro%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6222e31163c00bd376c316839465130c/href">https://medium.com/media/6222e31163c00bd376c316839465130c/href</a></iframe><p><strong>9. Use Service worker:</strong></p><figure><img alt="Service Worker Flow" src="https://cdn-images-1.medium.com/max/1024/1*ZqctvIBoiZaSAb_jtKQA8g.png" /><figcaption>Photo from <a href="https://mechanicalrock.github.io/2020/02/25/pwa-cache-me-if-you-can.html">Mechanical Rock Blogs</a></figcaption></figure><p>Service Worker acts as a proxy between the browser layer and the network layer.</p><p>The power of Service Worker is that you can use it as a cache before the network, and that way you are able to save the server access and receive the data from your local cache.</p><blockquote>Note: Service Worker also gives you the option to make <a href="https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps">PWA</a>.</blockquote><p>Of course we can’t apply it to all our API’s, so you need to think about what you want to cache.<br>At <a href="https://www.inx.co/">INX</a> we used it to cache all the vendors that are placed inside the Public folder that don’t need to be changed often.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d7c02a7180cfeea59d577be4609549c/href">https://medium.com/media/6d7c02a7180cfeea59d577be4609549c/href</a></iframe><h3>Conclusion</h3><p>The performance in trading systems is really important and as you can see above, with the help of some tools and a little analysis work you can improve every aspect of your program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*MZKwn_7GqnFYIPfe4isZZA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*owKCptDsNVyf8fQi3faJlA.png" /></figure><p>Hope you enjoyed and found it useful for your needs! 😀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa27d9f01a23" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>