Unveiling the Effects of Icons on Website Performance (part two)
Tags: performance, nextjs, react, beginners
Published: 2023-10-06 13:24:36

Hello and welcome back to the next part of our session. In the previous session, we delved into the impact of [React Icons](https://react-icons.github.io/react-icons/) on web performance, and if you missed it, you can catch up by visiting [Part One](https://dev.to/kporus/unveiling-the-effects-of-icons-on-website-performance-53lm). Now, it's time to roll up our sleeves and explore some effective approaches to reduce page load times and enhance overall web performance.

When it comes to web development, speed matters—a lot. It's not just about delivering content; it's about delivering it swiftly and efficiently. Slow-loading pages can be a major turn-off for users and can negatively affect your website's search engine rankings.

So, without further ado, let's dive into the strategies and techniques I've discovered to optimize web performance and provide users with a smoother, faster experience.

Before we proceed, please note that the approaches I'm about to share are based on my findings and experiences. I'm not endorsing any specific tool or method, and I'm open to learning from others. If you have a better solution or insight to offer, I encourage you to leave a comment or reach out to me via email. I'm eager to explore all available solutions and continue our collective journey toward improved web performance.

Let's get started! 🚀

At the outset, I opted for [ANT DESIGN ICONS] (https://ant.design/components/icon) when it came to using icons in my web development projects. Why, might you ask? Well, it's incredibly convenient and lightweight. Unlike some icon libraries that require you to install the entire component library, Ant Design Icons offers a more streamlined approach.

With Ant Design Icons, you don't need to bloat your project with unnecessary components. Instead, you can selectively use just the icons you need. The installation process is a breeze. Just run the following command:

```
npm install @ant-design/icons --save
```
This minimalistic approach not only keeps your project lean but also helps optimize performance. After all, every byte matters when it comes to web performance.

![Code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dksnuzpdg43v53j96jcq.png)

Certainly, it's important to note that it's not just the choice of icon library that matters for web performance, but also how you integrate and use those icons in your code.

Efficient usage of icons can make a significant difference in loading times and resource utilization. It's not uncommon to see web developers inadvertently introduce performance bottlenecks by misusing or overloading their web pages with unnecessary icons. 

<u>**1. Using Ant Design Icons in the Navbar:**</u>

In my first approach, I made the strategic decision to integrate Ant Design Icons into the navigation bar of my website. Given that the navbar is a consistent element across all pages, this choice seemed natural and efficient.

Icons in the navbar serve a dual purpose—they enhance both functionality and aesthetics. They offer users visual cues, which make navigation more intuitive and engaging. However, it's crucial to strike a balance and avoid overwhelming the navbar with icons that don't serve a genuine purpose.

To achieve this, I followed a specific approach:

****Import Icons in a Separate File:****

 I created a separate file for importing icons. This file 
 houses all the icons I intended to use throughout the 
 website. Importing them in one place ensures that they are 
 fetched and included only once during the build process 
 Here's a glimpse of the code:

    
![Code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mglg4gqwui07hva0ngbh.png)

 ****Reusable Icons:****

By centralizing the icons in a single file, I made it possible to reuse these icons across multiple pages without the need to request them from Ant Design's server repeatedly. This approach significantly reduces page load times and optimizes the overall web performance.


![Code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4zd3fin01dg4qlu68g6v.png)

As you can see, this method ensures that icons are imported only once during the build process, sparing us from unnecessary server requests and benefiting the overall page load time.

<u>2. Use of SVG ICONS:</u>

 Many developers, including myself, have held the belief that using SVGs can negatively impact our web page's performance. However, over time, I've come to realize that it's not SVG themselves but rather how we use them that matters.

In my code, I adopted an approach where I treated SVGs as images in Next.js. This strategy allowed me to efficiently deploy SVGs as part of my web project.

Here's how I implemented it:

****Import SVGs as Images URL:****
I imported SVGs just like any other image file, as shown 
    below:

![Code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4sgumzoose5ej2l1i030.png)
 

****Use SVGs Where Needed:****

   Once imported, I could use these SVGs as images in my 
   components or pages, as demonstrated in the following code 
   snippet:

![Code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/55y0b5r1xw7xemk91b0p.png)

  This approach made it simple to incorporate SVG wherever I 
  needed them in my web application.

****Optimize SVG When Required:****

   While using SVGs as images, I also ensured that the SVGs 
   themselves were optimized for web use. This involved 
   optimizing their file sizes and ensuring that they didn't 
   contain unnecessary elements or attributes. This 
   optimization step is crucial for maintaining a fast-loading 
   website.
![Code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/25sv664no2ceehjecw2y.png)

In closing, I want to reiterate that these findings are a result of my exploration and experiences. Web development is a dynamic field, and there's always more to learn. There may be alternative approaches, new tools, or optimizations that I haven't encountered yet. If you come across any errors or have better solutions, please don't hesitate to share them.

The beauty of our developer community lies in our collective knowledge and our willingness to help one another grow. Let's continue to push the boundaries of web performance, learn from each other, and create even faster and more efficient websites.

Thank you for being a part of this journey, and let's keep the spirit of curiosity and collaboration alive in our pursuit of better web performance.

Happy coding, and may your websites always load swiftly! 🚀🚀