<?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 Celia Usero Navarro on Medium]]></title>
        <description><![CDATA[Stories by Celia Usero Navarro on Medium]]></description>
        <link>https://medium.com/@celiausero?source=rss-25ec1d41ca8c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*ihMAvNIEy6904YejQk_y2g.jpeg</url>
            <title>Stories by Celia Usero Navarro on Medium</title>
            <link>https://medium.com/@celiausero?source=rss-25ec1d41ca8c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 13:30:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@celiausero/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[A Story About Dynamic SVG Loading]]></title>
            <link>https://medium.com/busuu-tech/a-story-about-dynamic-svg-loading-82e97c3230d7?source=rss-25ec1d41ca8c------2</link>
            <guid isPermaLink="false">https://medium.com/p/82e97c3230d7</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[busuu]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[svg]]></category>
            <dc:creator><![CDATA[Celia Usero Navarro]]></dc:creator>
            <pubDate>Tue, 15 Oct 2019 10:39:17 GMT</pubDate>
            <atom:updated>2019-12-19T10:27:26.784Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ozrRi2yboC2oGlnDRuOfwg.jpeg" /><figcaption><a href="https://unsplash.com/photos/cNcX6PPjEm8">Photo by Bogdan Karlenko on Unsplash</a></figcaption></figure><p>¡Hola! I’m Celia 😊</p><p>I’ve been working at <a href="https://www.busuu.com/">Busuu</a> as a front-end engineer for ~1 year. As part of the web team, we take care of four distinct projects:</p><ul><li>Homepage: encompasses all the public facing pages. Static webpage with server side rendering (Twig / PHP) that sits on a Grav content management system (CMS).</li><li>WebApp: once the user is authenticated, all the learning magic happens here! Single page application currently being migrated from Angular 1 to React.</li><li>Slate: CMS used by the Education Team to create lessons, units, exercises of the 12 different languages we offer. Single page application based on React &amp; Redux with Material-UI.</li><li>Management Platform: tool used by the learning admins from our B2B customers, to gain insight of the progress that students are making. It is a single page app based on Angular 1.</li></ul><p>The story I’m about to tell is specific to our WebApp — where all the magical language learning happens. This ranges from A1 to B2 levels, or specific industry courses, carefully crafted and split into bite sized lessons and units 🌐</p><h3>🖌 A bit about SVGs</h3><p>What’s great about Scalable Vector Graphics? In a nutshell 🤗:</p><ul><li>Easy to scale without losing quality</li><li>Straightforward when it comes to styling</li><li><em>Usually</em> small in size</li></ul><p>Although with great power also comes great responsibility, and the art of editing and manipulating SVGs can be slightly daunting at first. In addition, as they grow in popularity, their complexity means that the general file size is increasing. Nevertheless, the pros outweigh the cons!</p><p>Loading these in your HTML can be done in many ways, but I will focus on the two main methods that we use:</p><ul><li>Inline: a semantic &lt;svg&gt; tag added in your HTML will just work! It’s also SEO friendly if the correct keywords are used to name the layers.</li><li>External: loads the .svg file dynamically from an external source.</li></ul><h3>💾 Our past situation</h3><p>Our application is a Single Page Application (SPA) where most of the views and logic live inside the main JavaScript bundle. Unfortunately, it also means that every single svg file was part of that main bundle. Why were the icons for the Settings page being loaded, even though you had landed on the dashboard? 🤔</p><p>Based on what I previously mentioned about ways of loading SVGs, these were our two main approaches, scattered around the app:</p><h4>Static loading</h4><ul><li>How it works: we created a component (&lt;svg-replace&gt;) that would inject the *actual* SVG when Webpack bundles the app.</li><li>Pros: loading the icon doesn’t rely on extra network calls</li><li>Cons: repeated icons in the source and taking up precious kB 🎈</li></ul><pre>&lt;span class=&quot;icon icon--warning&quot;&gt;<br>    &lt;svg width=&quot;30&quot; height=&quot;30&quot;&gt;&lt;path&gt;...&lt;/path&gt;&lt;/svg&gt;<br>&lt;/span&gt;</pre><h4>Dynamic loading</h4><ul><li>How it works: &lt;SvgLoader /&gt; is a React component that takes the name of the icon, fetches it and applies the relevant styling</li><li>Pros: less repeated icons in the source and browser caching (just like an image resource)</li><li>Cons: one network call needed per icon — risky on flaky connections 💻</li></ul><pre>&lt;div class=&quot;cancel__header-icon&quot;&gt;<br>    &lt;SvgLoader icon=&quot;icon_gift&quot;&gt;&lt;/SvgLoader&gt;<br>&lt;/div&gt;</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c08926ea671ad12f417ef7e6e00a98aa/href">https://medium.com/media/c08926ea671ad12f417ef7e6e00a98aa/href</a></iframe><p>I needed a plan to load SVGs across the app consistently and efficiently!</p><h3>🕵️‍♀️ Slimming down</h3><h4>Part 1</h4><p>What were the must-have icons as soon as the user landed on the most popular page? If possible, these *should* be living in the source straight away, preventing missing icons!</p><p>The obvious ones to be inlined: top and side navigation bars. The remaining ones, such as the flags and exercise types _need_ to be dynamically fetched, since every course is shaped differently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w0gtEfcDO2neXs_C76b3lw.png" /><figcaption>Busuu Web Application — Complete Spanish course</figcaption></figure><h4>Part 2</h4><p>Before making all the other icons dynamic, deleting the unused ones was necessary. With a bit of spring cleaning, the icon count (not including country flags 😱) went from 158 down to 123.</p><p>Another step was to reuse as many common icons as possible, as an example, having a single chevron and styling it depending where it’s used. A simple rotate transformation to replace 4 SVGs! ⬅️ ➡️</p><pre>.vocab-list-row__arrow .icon {</pre><pre><em>    transform</em>: rotate(180deg);</pre><pre>}</pre><p>Similarly, with the fill colour, making it as flexible as possible! You might have already seen hardcoded fill colours embedded in the paths: &lt;path fill=&quot;#DDE0E3&quot; d=&quot;7.5...&gt;. Having shared icon stylesheets makes it easier to keep it consistent, and you can simply pass the styles to your dynamic component like: &lt;SvgLoader icon=&quot;icon_audio&quot; styles=&quot;icon--brand-base&quot;/&gt;</p><h4>Part 3</h4><p>By this point, I was in a good shape to start replacing everything with our dynamic-SVG-fetching-component 🎊</p><p>With a service that would take care of the HTTP fetch, there was another small issue. Every single time that an icon was needed, a request would take place 🙀</p><p>Here is when saving promises came to the rescue! Special thanks to <a href="https://medium.com/u/be99dc66f8f3">Liam Tarpey</a> for the inspiration 🦆</p><p>General idea of the code below:<br>1. Please, fetch the the icon_bell icon from the server<br>2. Do I already have a resolved Promise saved? AKA I’ve seen this icon before and I cached it 👀<br> * <strong>Yep</strong>: Have it here! No network call needed 😎<br> * <strong>Nope</strong>: I’ll make an HTTP get request and save it in my promise goodie bag, for next time 🐾</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1ef59fa809dfe890296f3251fb9392d/href">https://medium.com/media/c1ef59fa809dfe890296f3251fb9392d/href</a></iframe><h3>📈 A happy ending</h3><p>Measuring the results and improvement was very straightforward by checking the size of main.js — the final bundled up file that sits in our CDN.</p><h4>main.js before 😬 😬 😬 2.9MB ~ 842kB gzipped</h4><h4>main.js after 🥁 🥁 🥁 2.5MB ~ 743kB gzipped</h4><p>There you go! Following three relatively straightforward steps, you can save having a JS source file that is too bloated by inlined SVGs 😊</p><p>If you’re into performant web applications, and want to find out more about modularisation and code splitting, we are also onto that! Super interesting article by <a href="https://medium.com/u/be99dc66f8f3">Liam Tarpey</a> — <a href="https://tech.busuu.com/code-splitting-our-react-app-7c0cdf2a79a9">‘Code splitting our React app’</a> ! 👏</p><p>Hope you enjoyed reading! Below are a few useful links.</p><h3>🌈 Inspiration</h3><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/SVG">https://developer.mozilla.org/en-US/docs/Web/SVG</a></li><li><a href="https://css-tricks.com/using-svg/">https://css-tricks.com/using-svg/</a></li><li><a href="http://css-tricks.com/svg-use-external-source/">http://css-tricks.com/svg-use-external-source/</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Adding_vector_graphics_to_the_Web">https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Adding_vector_graphics_to_the_Web</a></li><li><a href="https://www.hallme.com/blog/benefits-of-svg-vector-graphics/">https://www.hallme.com/blog/benefits-of-svg-vector-graphics/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82e97c3230d7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/busuu-tech/a-story-about-dynamic-svg-loading-82e97c3230d7">A Story About Dynamic SVG Loading</a> was originally published in <a href="https://medium.com/busuu-tech">Busuu Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>