<?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 Javier on Medium]]></title>
        <description><![CDATA[Stories by Javier on Medium]]></description>
        <link>https://medium.com/@jahvi?source=rss-a2ed5b4c8a17------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vqlGdc5laCZUob5DrquI3A.jpeg</url>
            <title>Stories by Javier on Medium</title>
            <link>https://medium.com/@jahvi?source=rss-a2ed5b4c8a17------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 03:37:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jahvi/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[How to split UTXOs to isolate rare sats for inscriptions?]]></title>
            <link>https://medium.com/@jahvi/how-to-split-utxos-to-isolate-rare-sats-for-inscriptions-967c22f7df64?source=rss-a2ed5b4c8a17------2</link>
            <guid isPermaLink="false">https://medium.com/p/967c22f7df64</guid>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[satoshi]]></category>
            <category><![CDATA[ordinal]]></category>
            <category><![CDATA[inscription]]></category>
            <category><![CDATA[ordinals-protocol]]></category>
            <dc:creator><![CDATA[Javier]]></dc:creator>
            <pubDate>Tue, 30 Apr 2024 16:15:20 GMT</pubDate>
            <atom:updated>2024-04-30T16:15:20.964Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YA7BeEFqSZYv3uHMv1pwPA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@jievani?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Jievani Weerasinghe</a></figcaption></figure><p>If you’ve delved into the world of Bitcoin, you’ve likely come across the term “UTXO” or “Unspent Transaction Output.” These seemingly obscure words hold the key to grasping how Bitcoin transactions truly work under the hood. Despite their technical-sounding name, UTXOs are a fundamental concept that underpins the entire Bitcoin system and this of course include Inscriptions as well.</p><p>When inscribing ordinals you normally don’t have to worry about UTXOs because the complexities are handled for you behind the scenes (eg: if you are using something like the ord client). But if you want to inscribe on specific sats (say you want to use rare sats, sats with a cool name, etc) you need to dig a little bit deeper.</p><p>But before diving into the deep end we first need to make sure we got our basics covered.</p><h3>What are UTXOs?</h3><p>At its core, Bitcoin is a decentralized ledger that records every transaction that has ever occurred on its network. However, unlike traditional banking systems, Bitcoin doesn’t deal with account balances in the traditional sense. Instead, it relies on UTXOs — unique chunks of Bitcoin that act as the building blocks for all transactions.</p><p>Imagine your Bitcoin wallet as a container holding various denominations of Bitcoin, similar to having a physical wallet filled with different bills and coins. When you want to make a payment, your wallet doesn’t simply transfer the entire balance. Instead, it selects specific UTXOs, similar to picking out the necessary bills and coins, to fund the transaction.</p><p>UTXOs represent the unspent outputs from previous transactions on the Bitcoin network. They can be thought of as individual “piles” of Bitcoin that have been received but not yet spent. Each UTXO has a specific amount associated with it, ranging from a few Satoshis to multiple whole Bitcoins.</p><p>When you initiate a new transaction, your Bitcoin wallet will automatically select one or more of your available UTXOs to cover the amount you wish to send. Any remaining Bitcoin from those combined UTXOs is then sent back to your wallet as a new UTXO, ready to be used in future transactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pKxiKZaxzvFoTMq9S1bngA.jpeg" /><figcaption>Example transaction using 1 UTXO as input and creating 4 UTXOs as outputs.</figcaption></figure><p>This UTXO model is a fundamental departure from traditional banking systems, where account balances are tracked as a single, indivisible amount. By breaking down Bitcoin into discrete UTXOs, the system achieves a level of granularity and auditability that is crucial for a decentralized, trustless network.</p><h3>What do UTXOs have to do with Inscriptions?</h3><p>Inscriptions are a way of storing arbitrary data directly on the Bitcoin blockchain. By embedding data like images, videos, audio files, or even plain text into individual Satoshis, people can create immutable and decentralized digital artifacts. These inscribed Satoshis, often referred to as “Inscribed Bitcoin” or “Ordinals,” can be traded, collected, or held like any other Bitcoin amount, but with the added value of the inscribed content they carry.</p><p>Now let’s say you have a rare Satoshi and you want to inscribe something on it using the <a href="https://github.com/ordinals/ord/">ord</a> client. Using the --satpoint option you will be able to inscribe on specific UTXOs as well as specific Satoshis within that UTXO (using the &lt;txid&gt;:&lt;vout&gt;:&lt;offset&gt; format), however what if you have multiple Satoshis in the same UTXO that you want to manage individually?</p><h3>Enter UTXO splitting</h3><p>Before getting into specifics there’s two key concepts we need to understand to be able to split UTXOs effectively:</p><h3>1. UTXOs have a minimum size</h3><p>There is a concept known as the “dust limit.” This refers to the minimum amount of Bitcoin that a UTXO must contain to be considered valid and spendable. Outputs below this dust limit are typically rejected by the network to prevent spam and bloat on the blockchain.</p><p>Dust limits are different depending on the address type:</p><ul><li><strong>P2PKH addresses (starting with ‘1’):</strong> Minimum UTXO size of 546 satoshis.</li><li><strong>P2SH-P2WPKH addresses (starting with ‘3’):</strong> Minimum UTXO size of 540 satoshis.</li><li><strong>P2WPKH addresses (starting with ‘bc1q’):</strong> Minimum UTXO size of 294 satoshis.</li><li><strong>P2TR addresses (starting with ‘bc1p’):</strong> Minimum UTXO size of 330 satoshis.</li></ul><p>This means you can’t have a single inscribed Satoshi but instead this will have to live in a “pile” with other Satoshis in the same UTXO.</p><p>To visualize this you can check the inscription page in <a href="https://ordinals.com/inscription/0">ordinals.com</a> and have a look at the number under “value”. This is the number of Satoshis in the UTXO where the inscription lives.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NC1BQm0A4NLckrLdYN_3wA.jpeg" /><figcaption>Inscription 0</figcaption></figure><blockquote>If you want to dig deeper, the last number in the “location” value will tell you what position in this pile the inscription lives in.</blockquote><p>This should help you understand why most inscriptions have a value of <strong>546</strong>, because this will make them transferable across all addresses types. However most modern wallets use <strong>bc1…</strong> addresses so using a value of <strong>330</strong> is usually safe.</p><blockquote>This “value” is also referred to as “postage” in the ord client.</blockquote><h3>2. Ordinals are transferred input to outputs first-in-first-out</h3><p>Ordinal theory numbers Satoshis in the order in which they’re mined, and transferred from transaction inputs to transaction outputs first-in-first-out. This system is called the first-in-first-out algorithm.</p><p>This means that the same Satoshi in an input will be transferred to its same position in an output.</p><p>Let’s visualize this to understand this better:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u93rRBkwVoMG8RJ380sXJw.jpeg" /><figcaption>Correct expected transaction</figcaption></figure><p>In this example we have one UTXO as input with 2,000 sats and 2 outputs with 1,000 sats each. The Satoshis from the top half of the “pile” were transferred to the first output while the bottom half was transferred to the second output.</p><p>This means <strong>you can’t do something like the following</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*41kmsmBBUsy45hkXdiafSw.jpeg" /><figcaption>Incorrect expected transaction</figcaption></figure><p>We won’t be able to split the R<strong>ed Satoshis </strong>this way because the outputs are not in the same order. So using the same values the expected result will be something like this instead:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iTSwS_RMwGfH2AyGoCMI9A.jpeg" /><figcaption>Correct expected transaction</figcaption></figure><p>As you can see the second output will end up with <strong>the bottom half of the Red Satoshis and the top half of the Green Satoshis, </strong>and the third output will end up with the rest of the <strong>Green Satoshis.</strong></p><blockquote>We’re ignoring fees for simplicity but they will come into play later on.</blockquote><h3>Isolating specific Satoshis</h3><p>Understanding these two concepts are the most important thing to learn how to isolate individual Satoshis.</p><p>Now that we got them out of the way let’s go over a few practical examples:</p><h3>1. Identify the Satoshi’s position in the UTXO</h3><p>Let’s say we have a UTXO with <strong>2,000 Satoshis</strong> and we want to inscribe in <strong>Satoshi #660</strong> in the “pile”. We want this Satoshi to live in a UTXO <strong>at the top of the pile</strong> so we can inscribe using the ord client.</p><blockquote>We can actually inscribe this as it is using the satpoint option like: --satpoint ABC:0:659 but we’ll move it to the top of the UTXO to make the next examples easier to understand.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ebXEaGpuCKULM0D8q94iAw.jpeg" /><figcaption>Starting UTXO</figcaption></figure><p>Let’s say we want to isolate <strong>Satoshi #660</strong> in a single <strong>546 Satoshis</strong> UTXO, based on what we know we need to split this into <strong>3 different outputs</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9p0D1aBFxgjUQ9MYQ-ZRMg.jpeg" /><figcaption>Transaction with 3 outputs</figcaption></figure><p>In this example we create 3 separate outputs:</p><ol><li><strong>Output DEF:0 (659 sats)</strong>: This will “remove” the sats above the sat we want to isolate (<strong>Satoshi #660</strong>)</li><li><strong>Output DEF:1 (546 sats)</strong>: Now with <strong>Satoshi #660 </strong>at the top of the “pile” we can create another output with the number of sats we want out postage to be (546 sats)</li><li><strong>Output DEF:2 (1,100 sats)</strong>: We create a new output with the leftover sats (excluding fees)</li><li>The rest (105 sats) are left as miner fees.</li></ol><blockquote>Always keep in mind fees are taken from the “bottom of the pile”.</blockquote><p>Now with out Satoshi isolated we can inscribe it using the ord client using a command like this:</p><pre>ord wallet inscribe --fee-rate 10 --file inscription.txt --satpoint DEF:1:0 </pre><p>This was a very simple example so let’s see how a more complicated example would look like:</p><p>We want to <strong>isolate sats #600 and #700 in a 2,000 sats UTXO:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*XEDvMOQARAndj_9Vhd3UhA.jpeg" /><figcaption>Starrting UTXO</figcaption></figure><p>In this example we have a new complication: <strong>there are unwanted sats in between the sats we want to isolate</strong> and, worst of all, t<strong>hey are below the dust limit</strong> so we can’t easily split them out.</p><blockquote>If we use the satpoint option in ord to inscribe the highest numbered Satoshi first, ord will keep the lower numbered one in a cardinal output but this approach still illustrates how you would go about isolating them manually.</blockquote><p>There’s a few ways we can go about this but we will need more than one transaction to get to our desired outcome:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qb4bwUpGoxUxCqRl1G-22g.jpeg" /><figcaption>First transaction</figcaption></figure><p>First we split the inputs into two outputs:</p><ol><li><strong>Output DEF:0 (600 sats)</strong>: This will leave <strong>Satoshi #600</strong> at the bottom of the “pile.</li><li><strong>Output DEF:1 (1,300 sats)</strong>: This will leave <strong>Satoshit #700 </strong>still below 100 common Satoshis.</li><li>The rest (100 sats) are left as miner fees.</li></ol><p>Now with these 2 new UTXOs we can create a new transaction, however to get around the dust limit we need to include a <strong>third UTXO with common Satoshis</strong> as “padding” to allow us to fill the space between the 2 UTXOs to allow us to isolate them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E57S8rUQgN5Y4Q4XF5-gIQ.jpeg" /></figure><p>In this step we added a “New” UTXO in between out previous one to act as “padding” so we end up with:</p><ol><li><strong>Output JKL:0 (599 sats)</strong>: This will “remove” the sats above the sat we want to isolate (<strong>Satoshi #600</strong>)</li><li><strong>Output JKL:1 (546 sats)</strong>: Now with <strong>Satoshi #600 </strong>at the top of the “pile”.</li><li><strong>Output JKL:2 (1,455 sats)</strong>: This will remove the “padding” and leave <strong>Satoshi #700 </strong>at the top of the “pile”.</li><li><strong>Output JKL:3 (546 sats): </strong>Now with <strong>Satoshi #700 </strong>at the top of the “pile”.</li><li>For the sake of simplicity I’m leaving the rest (754 sats) as miner fees but we can probably split this out into another output so we don’t spend that much in fees.</li></ol><p>As you can see this can get very complicated very quickly, but once you understand the basics then any Satoshi can be isolated by using a combination of the examples mentioned above.</p><h3>Isolating every sat in a UTXO</h3><p>This is where things really start to get interesting, for example if we want to isolate a single <strong>500 sats UTXO into 500 individual UTXOs </strong>then we’ll need to start getting more clever.</p><p>Again, there’s a few ways to achieve this but this is my preferred method:</p><h4>Setup</h4><p>First we’ll need to prepare the final UTXOs, if we want to use <strong>546 sats UTXOs</strong> we need to first create a transaction to create <strong>500 UTXOs with 545 Satoshis each,</strong> we will include the isolated Satoshi at the top in the end so it’ll give us our final value of <strong>546.</strong></p><p>Now since we want to isolate every Satoshi we need to also include an extra UTXO to pay for fees otherwise <strong>we can accidentally spend the sats we want to isolate.</strong></p><h4>The easy but time consuming way</h4><p>The easiest way to go from here is to isolate sats from the bottom of the pile, this is pretty straightforward but time consuming since <strong>you will need to create 500 transactions</strong> to isolate every sat.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ioi0Kk8QUuc5Cg4dABgJmg.jpeg" /><figcaption>Isolating a single Satoshi</figcaption></figure><ol><li><strong>Output DEF:0 (499 sats)</strong>: This are the rest of the sats we want to isolate, we create a new UTXO with all but one.</li><li><strong>Output DEF:1 (546 sats)</strong>: The isolated satoshi, we take the Satoshi at the bottom of the first “pile” and combine it with one of our previously prepared “common” UTXO.</li><li><strong>Output DEF:2 (900 sats)</strong>: This is the change, the amount of the last input is not that important just make sure it’s enough to pay for the fees and create a new output with the difference so we can spend later.</li><li>The rest (100 sats) is for miner fees.</li></ol><p>If you don’t have many sats to isolate then this approach might be fine, you can also script this and create up to 25 transactions that reference the previous transaction IDs so you can <strong>potentially</strong> <strong>isolate 25 Satoshis per block</strong> and speed up the process considerably.</p><p>Another easy way would be to directly use the rare sats UTXO in conjunction with the satpoint command. You can directly inscribe on the last sat of the “pile” and ord will safely send the sats at the top of the stack to a different UTXO. This way you can isolate and inscribe at the same time.</p><blockquote>It’s a good idea to add more than 546 sats to the top of the “pile” you want to isolate before doing anything, this way you avoid any surprizes if the UTXO “pile” starts getting smaller than the dust limit.</blockquote><p>Since inscriptions are actually two different transactions (commit + reveal) you will only be able to do <strong>12 at a time to stay below the 25 transaction limit</strong>.</p><h4>The hard but more efficient way</h4><p>The main issue with the previous approach is that we only have one “pile” we can use to isolate Satoshis from the bottom from, but if we had multiple “piles” we would be able to speed up the process exponentially.</p><p>So let’s try creating two piles so we can isolate 2 Satoshis at a time.</p><p>First we need to <strong>split the first UTXO into two halves</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SHIJwwAO78x6N5AWis8uYw.jpeg" /><figcaption>First split</figcaption></figure><p>As you can see we split the sats to isolate into <strong>two</strong> <strong>250 halves </strong>and added common sats <strong>before and after</strong>. The amount of common sats should be enough to account for dust limits and future splits (more on this later).</p><p>Now we repeat the process again starting with the previous UTXOs as inputs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a74RRhfuWznn5Dv2tmAB1w.jpeg" /><figcaption>Second split, two outputs with sats to isolate at the bottom</figcaption></figure><p>After we split the UTXOs a second time we end up with 5 outputs:</p><ul><li><strong>Output JKL:0 and JKL:2 (2,125 sats): </strong>UTXOs with the sats to isolate at the bottom of the “pile”</li><li><strong>Output JKL:1 and JKL:3 (2,125 sats): </strong>UTXOs with the sats to isolate at the top of the “pile”.</li><li><strong>Output JKL:4 (900 sats): </strong>Fee change.</li><li>The rest (100 sats) is for miner fees.</li></ul><p>Now with 2 UTXOs with the sats to isolate at the bottom we can repeat the steps from the first approach, only this time <strong>we will be able to isolate two Satoshis at a time instead of one</strong>.</p><p>With only a bit of preparation <strong>we have doubled the amount of Satoshis we can isolate</strong>, we can continue preparing more UTXOs so instead we start with four, eight, sixteen or more outputs and increase our efficiency by multiple orders of magnitude.</p><h3>How to do this in practice?</h3><p>In real life you will want to script this process as much as possible using your preferred coding language, this should help avoid accidentally spending your rare sats and chain multiple transactions more easily if you want them to get confirmed more quickly.</p><p>However you can use Sparrow’s Coin Control feature to achieve this (to some extent).</p><p>If you select the UTXOs you want to spend you can add multiple outputs with custom amounts, these should both match any of the approaches we outlined before:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ygHdexGhhoa23R25zOR8JQ.jpeg" /><figcaption>Sparrow UI</figcaption></figure><p>I found it easier to label the outputs with numbers so I can double check the correct order before sending the transaction. <strong>Sometimes Sparrow bugs out and doesn’t show the correct labels in the next step so triple check everything.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*-wuVCaS4Hn2ZS3Ca5NA9Vw.gif" /><figcaption>Reordering transactions</figcaption></figure><blockquote>Be very careful before sending the transaction, if the inputs and outputs are not in the correct order you will risk spending your rare Satoshis by mistake.</blockquote><p>If you want to know more about UTXO control using Sparrow you can <a href="https://www.youtube.com/watch?v=z8gtUPtji1c">watch this video by Franken</a> where he goes through the whole process in more detail.</p><p>Understanding UTXOs is key when trying to do complex transactions in the Bitcoin Blockchain or you might risk losing your rare sats, inscriptions and runes by making avoidable mistakes. It requires some technical knowledge but hopefully this article can help people going through their learning process.</p><p>Big shoutouts to <a href="https://twitter.com/gm7t2">Greg</a> whose help was absolutely invaluable for me when trying to understand this myself.</p><p>If you need any help feel free to reach out to me at “jahvi” in the <a href="https://discord.com/invite/ordinals">Ordicord Discord Server</a>. 👋🏽</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=967c22f7df64" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Storyblok Visual Editor Integration for Magento 2]]></title>
            <link>https://medium.com/@jahvi/storyblok-visual-editor-integration-for-magento-2-1a6de3035d3a?source=rss-a2ed5b4c8a17------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a6de3035d3a</guid>
            <category><![CDATA[storyblok]]></category>
            <category><![CDATA[magento]]></category>
            <category><![CDATA[headless]]></category>
            <category><![CDATA[magento-2]]></category>
            <category><![CDATA[page-builder]]></category>
            <dc:creator><![CDATA[Javier]]></dc:creator>
            <pubDate>Mon, 08 Mar 2021 13:07:50 GMT</pubDate>
            <atom:updated>2021-03-08T13:07:50.767Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*er43rcJEYepgzSpSD_JHeQ.jpeg" /><figcaption>Magento 2 Storyblok Integration</figcaption></figure><p>For a while now at <a href="https://medialounge.co.uk/">Media Lounge</a> we’ve been looking for the best solution to deliver a rich content driven experience that’s not only easy for store owners and maintainers to use but also for developers and agencies to build with and extend.</p><p>We’ve always found the current state of content management for Magento 2 very limited, if you’ve used Magento for a significant amount of time you’ll be familiar with some of these approaches:</p><h3>CMS Pages</h3><p>If you need to create a standalone page for your e-commerce store you will probably start with these. Magento provides a WYSIWYG editor powered by TinyMCE that lets us add almost any kind of HTML content that we want and, while this works fine for simple pages, it can become harder to maintain the more complex the page layout gets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A0oRS2aGeF-o0-qU9OKzUQ.png" /><figcaption>CMS Pages WYSIWYG</figcaption></figure><p>Editing content like this requires good knowledge of HTML and even that doesn’t solve all the problems. What if you need custom CSS or JS? What about variable content? You can’t even preview how the page is going to look like before saving it so it’s hard to fix mistakes without publishing the content first.</p><h3>Static Blocks</h3><p>Static Blocks (or just Blocks) can be very useful since they let us make sections of a page editable, this way we can extract the complex parts of the content to the Magento template (HTML, CSS, JS, etc) and only focus about the editable parts of the elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dKDXXwOe2hfgwC2i_1E1vw.png" /><figcaption>CMS Block</figcaption></figure><p>This is convenient but it doesn’t solve all problems, you will probably need to keep <em>some</em> HTML in the block still and splitting editable areas into multiple blocks can become dozens or even hundreds of blocks that will need to be managed, and the admin interface doesn’t make this easy.</p><h3>Widgets</h3><p>Widgets are Magento’s answer to some of the problems mentioned before, they let us abstract the complexities of editable content (HTML, CSS, JS, etc) behind an “easy” to use interface.</p><p>They were our go-to solution for most content editing needs but it always felt like the lesser of two (or in this case three?) evils, you still need a lot of boilerplate code to even get the simplest widgets to work and out of the box they only provide a handful of field types you can use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BM_mKY0OFQtjneWnRVkWSg.png" /><figcaption>Our custom “multi field” widget</figcaption></figure><p>A lot of our clients like content-rich e-commerce sites that are easy for them to edit and we felt that we were already pushing the limits of what Magento offers out of the box.</p><h3>What about Magento Commerce’s Page Builder?</h3><p>Magento Commerce’s Page Builder is a Magento extension for creating content, in a way it’s better than the solutions mentioned before as some of its key features are:</p><ul><li><strong>Drag-and-drop</strong> functionality for content creation.</li><li><strong>Live previews</strong> of how the content will look on the storefront.</li><li><strong>Form editors</strong> for entering and customising the content.</li></ul><p>However there are still quite a few downsides that we didn’t like:</p><ul><li><strong>Magento Commerce only </strong>with no certainty of ever coming to Magento Open Source.</li><li><strong>Lots of boilerplate</strong> even more so than widgets.</li><li><strong>Using the default Magento frontend stack</strong> who likes Knockout and uiComponents??</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*faf1VWxfDRy7a20UntRNCQ.png" /><figcaption>Magento Commerce Page Builder</figcaption></figure><p>Because of this we decided to start looking outwards, there are some good alternatives out there in the form of Magento Extensions or third party services if you prefer the Headless approach, but after careful consideration we decided to use <a href="https://www.storyblok.com/"><strong>Storyblok</strong></a> as our content management solution.</p><h3>Why Storyblok?</h3><p><strong>Storyblok</strong> allows you to manage content through a CMS that is intuitive, powerful, and easy to use. It offers a unique combination of visual editing tools and highly customisable content blocks on top of a modern headless architecture that gives you the flexibility to build fast and reliable content experiences.</p><p>While working entirely through their API, <strong>Storyblok</strong> gives integrators and developers total flexibility with the benefit of a dedicated and stand-alone best in class CMS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*72lygdjrhcl6dkfh.png" /><figcaption>Storyblok Visual Editor</figcaption></figure><p><strong>Storyblok</strong> provides features comparable to Magento’s Page Builder:</p><ul><li>Pages with Visual Editor</li><li>Editable Sections</li><li>Custom Fields</li><li>Internationalisation Support</li><li>Content Scheduling, <strong>and more!</strong></li></ul><p>The more we used it the quicker we realised <strong>Storyblok</strong> was better than any other content management alternative we had used in the past, it’s extremely easy for regular users and store owners to edit their website’s content without any code involved.</p><p>So we decided to create our own extension to integrate <strong>Storyblok’s</strong> Visual Editor with Magento 2 in a way that’s also very easy for developers to create and customise even the most complex of layouts.</p><h3>Storyblok Integration for Magento 2</h3><p>Our Magento 2 integration allows developers and digital agencies to create content-rich pages that are easily editable using the Storyblok interface. It can be used as an <strong>alternative to Magento Commerce’s Page Builder </strong>as it provides all of its features and, combined with our integration module, it allows for a more pleasant developer experience when it comes to creating custom blocks.</p><p>We tried to keep the integration as seamless as possible by sticking to “the Magento way” so you won’t need to learn any new concepts or technologies. Let’s see this in action with a quick example.</p><blockquote>Before we start we’ll need to <a href="https://www.storyblok.com/">create an account in Storyblok</a>, you can start by using their free tier but you will definitely want to upgrade to one of their paid plans if you want to use the more powerful features.</blockquote><h3>Installation</h3><p>Our Storyblock Integration module is available in the <a href="https://marketplace.magento.com/medialounge-magento2-storyblok-integration.html">Magento Marketplace</a> so we can install it the same way as any other Magento 2 module, in the project root run:</p><pre>composer require medialounge/magento2-storyblok-integration<br>php bin/magento setup:upgrade</pre><blockquote>The module only lists Magento 2.4 in the Magento Marketplace but it does work with Magento 2.3 as long as it’s running PHP 7.3 or later. You can also install it <a href="https://packagist.org/packages/medialounge/magento2-storyblok-integration">directly from Packagist</a>.</blockquote><h3>Creating our first page</h3><p>After we install and configure our module we can start creating content in <strong>Storyblok</strong>, go to <strong>Content → + Entry</strong> and give it any name you want.</p><p>At first the page will look rather empty but you should be able to see a live preview of your Magento 2 website in the <strong>Storyblok Visual Editor</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EZ7_aAKUTu_r7ynfcDNtsA.png" /><figcaption>Visual Editor Preview</figcaption></figure><h3>Creating our first block</h3><p>Now for the fun part! Let’s create our first block. We’ll use one of the default Luma banners as inspiration to make it reusable across our site.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HKt6ZizvGrL6BE3ApKvxHg.png" /><figcaption>Luma Banner</figcaption></figure><p>We’ll need to create a new <strong>Block</strong> in Storyblok as well as assign it a <strong>Schema</strong> which is a fancy name to describe a set of fields.</p><p>We can structure the block’s schema in a few different ways but to showcase some of the <strong>Storyblok</strong> Integration module features let’s make it:</p><ol><li><strong>Background Image: </strong>Asset</li><li><strong>Title:</strong> Text</li><li><strong>Content:</strong> Richtext</li><li><strong>Button</strong>: Block (we’ll come back to this later)</li></ol><p>So after creating our <strong>Banner</strong> block it should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iBZ2u5FbbzoyqdmxLJrAfw.png" /><figcaption>Initial Banner Block</figcaption></figure><p>Because we don’t have a template for this block we end up with a debug message with all the data that we have available as well as the path where it expects the PHTML template file to be in, so we just need to create a new file in our custom theme.</p><p><strong>MediaLounge_Storyblok/templates/story/banner.phtml</strong></p><pre>&lt;?php <br>/** <a href="http://twitter.com/var">@var</a> MediaLounge\Storyblok\Block\Container\Element $block */ <br>?&gt;</pre><pre>&lt;div class=&quot;block-promo&quot;&gt;<br>    &lt;img<br>        width=&quot;1280&quot;<br>        height=&quot;460&quot;<br>        src=&quot;&lt;?= $block-&gt;transformImage($block-&gt;getImage()[&#39;filename&#39;], &#39;1280x460&#39;) ?&gt;&quot; <br>        alt=&quot;&lt;?= __(&#39;New Luma Collection&#39;) ?&gt;&quot;<br>    &gt;</pre><pre>    &lt;span class=&quot;block-content&quot;&gt;<br>        &lt;span class=&quot;block-info&quot;&gt;&lt;?= $block-&gt;getTitle() ?&gt;&lt;/span&gt;</pre><pre>        &lt;?= $block-&gt;renderWysiwyg($block-&gt;getContent()) ?&gt;<br>    &lt;/span&gt;<br>&lt;/div&gt;</pre><p>This template works the same way as any other template that extends the Magento\Framework\View\Element\Template block class.</p><p>In here we have access to the <strong>Storyblok</strong> fields as part of the block’s data so you can access them by using the $block-&gt;getData(&#39;field_name&#39;) method or magic methods if you prefer $block-&gt;getFieldName().</p><p>You may have also noticed a couple special <strong>Helper methods</strong>:</p><p><strong>$block-&gt;renderWysiwyg(array $arrContent)</strong></p><p>When using “Richtext” fields this method will ensure that HTML elements are rendered.</p><p>In our example we use it to render the “Content” field’s data.</p><p><strong>$block-&gt;transformImage(string $image, string $param = ‘’)</strong></p><p><strong>Storyblok</strong> offers an <a href="https://www.storyblok.com/docs/image-service">Image Service</a> that allows you to transform image’s size, format, quality amongst other things. This method provides a convenient way of interacting with it so we are able to modify images on the fly.</p><p>In our example we can use it to enforce our image is always at most 1280x460 pixels in size.</p><p>After adding some CSS styles we should be able to see a live preview of our new block in <strong>Storyblok’s</strong> Visual Editor preview.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yvk1uCrolQB-ZkBJ-CwsOA.png" /><figcaption>Banner Block Preview</figcaption></figure><h3>Nesting blocks</h3><p>One of the best things about <strong>Storyblok</strong> is that it allows you to nest individual blocks into each other and our Magento 2 Integration module supports this feature as well.</p><p>We can put this into practice by making the button in our banner a standalone block, let’s repeat the same process as before and create a new <strong>Button</strong> block with the following schema:</p><ol><li><strong>Text: </strong>Text</li><li><strong>URL:</strong> Link</li></ol><p><strong>MediaLounge_Storyblok/templates/story/button.phtml</strong></p><pre>&lt;?php <br>/** <a href="http://twitter.com/var">@var</a> MediaLounge\Storyblok\Block\Container\Element $block */<br>?&gt;</pre><pre>&lt;a href=&quot;&lt;?= $block-&gt;getData(&#39;url&#39;)[&#39;cached_url&#39;] ?&gt;&quot;&gt;<br>    &lt;?= $block-&gt;getText() ?&gt;<br>&lt;/a&gt;</pre><p>After adding some CSS we should be able to use our new <strong>button</strong> as a standalone block in the <strong>Storyblok</strong> Visual Editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*waeHRutqwZvhJ0osbbgzNA.png" /><figcaption>Button Block</figcaption></figure><p>Now to use it on our <strong>banner</strong> block we need to edit its schema and include a new field with a type of <strong>Block</strong>, this will let us nest any kind of block inside our banner.</p><p>For our example let’s restrict this field a bit more, we can make it so only one components is allowed (the <strong>Button</strong> block) and also prevent multiple buttons from being added.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oxDMYnUdYdIG0M8Cvmf9YQ.png" /><figcaption>Button Block Field</figcaption></figure><p>Finally we need to edit our <strong>banner</strong> block template to specify where we want nested components to render, we can do this by using Magento’s method$block-&gt;getChildHtml().</p><pre>&lt;?php <br>/** <a href="http://twitter.com/var">@var</a> MediaLounge\Storyblok\Block\Container\Element $block */ <br>?&gt;<br>&lt;div class=&quot;block-promo&quot;&gt;<br>    &lt;img<br>        width=&quot;1280&quot;<br>        height=&quot;460&quot;<br>        src=&quot;&lt;?= $block-&gt;transformImage($block-&gt;getImage()[&#39;filename&#39;], &#39;1280x460&#39;) ?&gt;&quot; <br>        alt=&quot;&lt;?= __(&#39;New Luma Collection&#39;) ?&gt;&quot;<br>    &gt;<br>    &lt;span class=&quot;block-content&quot;&gt;<br>        &lt;span class=&quot;block-info&quot;&gt;&lt;?= $block-&gt;getTitle() ?&gt;&lt;/span&gt;<br>        &lt;?= $block-&gt;renderWysiwyg($block-&gt;getContent()) ?&gt;</pre><pre>        &lt;?= $block-&gt;getChildHtml() ?&gt;<br>    &lt;/span&gt;<br>&lt;/div&gt;</pre><p>This way our new <strong>button</strong> block will be rendered just under the banner’s content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1PqO-dwYzdPla96JvN_Png.png" /><figcaption>Banner Block with Button</figcaption></figure><p>From here on it’s just a matter of repeating the same process for all custom blocks and by adding some CSS and JS we can create from simple to very complex layouts using the <strong>Storyblok</strong> interface!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mlAV5hCeN0JIpFevAoPGRQ.gif" /><figcaption>Full Visual Editor Demo</figcaption></figure><h3>Editable Sections</h3><p>We don’t need to use <strong>Storyblok</strong> just to manage content for a whole page, we can also use it to make specific sections within our pages editable. This can be useful when we need elements like header menus, footer links, product-specific promotions, etc, where we would normally use <strong>Static Blocks</strong> or <strong>Widgets</strong>.</p><p>First, we need to create a new Entry in <strong>Storyblok</strong> but instead of using the “page” content type you should choose to create a new one that better matches the content that you’re trying to create.</p><p>After this <strong>Storyblok</strong> will open the content type in the preview window as a regular page, this is NOT what we want but let’s ignore it. For now, define the schema as you normally would.</p><p>Next we want to tell <strong>Storyblok</strong> what page should be displayed in the preview, you can change this in the sidebar by going to Config → Real Path. This depends on the kind of content that you want to manage, eg: to display the homepage use /, for the cart page use /checkout/cart and so on. Save the change and reload the page.</p><p>We should now see the Real Path in the preview screen but our new block is nowhere to be seen yet. We need to tell Magento where we want our block to be displayed and this is done using regular Layout XML directives:</p><pre>&lt;referenceContainer name=&quot;footer&quot;&gt;<br>    &lt;block class=&quot;MediaLounge\Storyblok\Block\Container&quot; name=&quot;storyblok.custom.block&quot;&gt;<br>        &lt;arguments&gt;<br>            &lt;argument name=&quot;slug&quot; xsi:type=&quot;string&quot;&gt;our-block-slug&lt;/argument&gt;<br>        &lt;/arguments&gt;<br>    &lt;/block&gt;<br>&lt;/referenceContainer&gt;</pre><p>As long as we use MediaLounge\Storyblok\Block\Container as the block class and pass the Storyblok slug as an argument we can display custom blocks anywhere we want, in this example we chose to display it inside the footer container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lbIHD-rkWQFizCkdLtQmFQ.png" /><figcaption>Editable Footer Block</figcaption></figure><p>Finally we just repeat the same process as before:</p><ol><li>Create the PHTML template</li><li>Style content</li><li>Publish</li></ol><h3>SEO</h3><p>We wanted to make sure that our <strong>Storyblok</strong> Integration didn’t impact SEO negatively so we made sure to enable the same SEO features that native CMS pages offer out of the box.</p><h3>Sitemap Integration</h3><p>Our <strong>Storyblok</strong> Integration will automatically include pages in the Magento built-in sitemap generator so they can be indexed by search engines.</p><blockquote>By default only pages with the Content Type of “page” will be included in the sitemap.</blockquote><h3>Custom SEO field</h3><p>The “meta-fields” custom field is an example of an extra block that can be used in a <strong>Storyblok Space</strong> and our Magento 2 module provides support for it out of the box.</p><p>We can add our SEO field type as part of our page’s schema, make sure to select “Plugin” under the <strong>Field Type</strong> and “meta-fields” as the <strong>Custom Type</strong>.</p><p>Now the page’s title and meta description will be editable from <strong>Storyblok</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fu17qmGQsA5kXrMwvSIOEw.png" /><figcaption>SEO Meta Fields Block</figcaption></figure><h3>Custom Fields</h3><p>On the subject of custom fields, one of the most powerful <strong>Storyblok</strong> features is that it gives us the power to extend fields with custom code to provide almost unlimited functionality that the built in fields might not give us.</p><p>Custom fields are built entirely on <strong>Storyblok’s</strong> end so there’s nothing special in our Integration Module to get them to work, you can create them as a plugin following their <a href="https://www.storyblok.com/docs/plugins/introduction">documentation</a> and then use a Helper or ViewModel in the Magento side to parse the data in any way you want.</p><p>For example, we can create a custom field that uses the Magento GraphQL API to query products so we are able to search, paginate and select products from <strong>Storyblok </strong>to display as part of a <strong>Featured Products Block</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sqj0aCFtu0NxGqyNelQ0yA.gif" /><figcaption>Magento Product Finder Custom Field</figcaption></figure><p>With custom fields the possibilities are almost endless!</p><h3>Performance</h3><p>We wanted to keep the <strong>Storyblok</strong> Integration module as lean as possible so its performance footprint on Magento 2 stores is very minimal. Out of the box <strong>our module doesn’t include blocks</strong>, in fact we don’t even add any extra CSS or JS to your Magento 2 store! We give you the freedom of customising your content any way you want using the technology stack of your choice.</p><p>We also use Magento’s cache tags to individually cache <strong>Storyblok </strong>content to avoid making unnecessary HTTP requests, and when this content is updated we only clear the cache tags for the affected blocks.</p><h3>Try it yourself!</h3><p>There’s a lot more features available in <strong>Storyblok </strong>that can be easily implemented using our <strong>Magento 2 Integration</strong>, we hope that you find it as useful as we have and if you have any issues feel free to report them in our official GitHub repository.</p><p>As mentioned before, you can get the integration module from:</p><ul><li><a href="https://marketplace.magento.com/medialounge-magento2-storyblok-integration.html">Magento Marketplace</a></li><li><a href="https://github.com/Media-Lounge/magento2-storyblok-integration/">GitHub Repository</a></li></ul><p>If you want to know more make sure to read the <a href="https://github.com/Media-Lounge/magento2-storyblok-integration/wiki">Documentation</a> or if you prefer the video format you can check out our <a href="https://www.youtube.com/watch?v=I8_TCyOCKAo&amp;list=PLn3mpLgxMjLSRWmmmf0RRX8wEVgv4dZ0k">YouTube playlist</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a6de3035d3a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimising images for better LCP web vitals scores]]></title>
            <link>https://itnext.io/optimising-images-for-better-lcp-web-vitals-scores-7e9866087973?source=rss-a2ed5b4c8a17------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e9866087973</guid>
            <category><![CDATA[page-speed]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[ecommerce]]></category>
            <category><![CDATA[page-speed-optimization]]></category>
            <dc:creator><![CDATA[Javier]]></dc:creator>
            <pubDate>Mon, 04 Jan 2021 13:12:24 GMT</pubDate>
            <atom:updated>2021-01-08T09:17:44.419Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nsdapYI0cZGGEbYqs3TSSw.jpeg" /><figcaption>Photo by Soragrit Wongsa</figcaption></figure><p>Images are some of the most common types of content used on the web, they’re often used to attract user’s attention and they are usually the biggest element on-screen above the fold (think of banners, hero images, product images, etc) so it’s very important we do the best we can to make them display as fast as possible to maintain a good user experience.</p><p>Taking a look at <a href="https://web.dev/vitals/">Google’s Web Vitals</a> there’s an important metric that images can affect and that is “<strong>Largest Contentful Paint</strong>” (LCP), considering this alone makes up to <strong>25%</strong> of the total Lighthouse score it is one metric that we can’t afford to ignore.</p><blockquote>The Largest Contentful Paint (LCP) metric reports the render time of the largest <a href="https://web.dev/lcp/#what-elements-are-considered">image or text block</a> visible within the viewport.</blockquote><p>If our largest element above the fold is an image (which is very likely specially on e-commerce websites) then optimising this image will make it render quicker and improve our Lighthouse scores at the same time. So, I’d like to share a few tips on how to improve LCP with some performance measurements to back them up.</p><h3>The Test Subject</h3><p>I’ll use the demo from my “<a href="https://itnext.io/javascript-sliders-will-kill-your-website-performance-5e4925570e2b">Javascript sliders will kill your website performance</a>” article because it’s very simple and it shows a layout that’s common in e-commerce product pages so hopefully you will be able to relate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*Z8dpu96Ge0-Qf55Hh2SJhQ.gif" /><figcaption>Initial demo</figcaption></figure><p>Here are the initial numbers, I included “<strong>First Contentful Paint</strong>” (FCP) as well just for reference as I didn’t want my optimisations on LCP to negatively impact FCP:</p><p><strong>FCP:</strong> 1.17s<br><strong>LCP:</strong> 1.59s<br><strong>Page Size</strong>: 67.8kb</p><blockquote>The performance tests were made using an iPhone 8 screen simulating a 3G connection (1.6 Mbps / 768 Kbps 300ms RTT)</blockquote><h3>Use the right image for the screen size</h3><p>This is one that’s sometimes very obvious but often overlooked, you won’t believe the amount of sites out there that ship images that are 3+ times bigger than they should because they just resize the desktop-sized images down.</p><p>As a rule of thumb try not to use images that are more than 2 times bigger than the size they are going to be displayed as, if you don’t mind losing some quality on HiDPI devices you can even go smaller than that. Use the srcset &lt;img&gt; attribute or the picture element to display the appropriate image for the screen size.</p><p>In my demo the product image is going to be displayed at about <strong>375px</strong> wide so I chose to use an <strong>750px</strong> wide image so it looks good on retina screens and modern devices.</p><p>Let’s see how our performance timeline looks right now:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*4Gb6cFVvDbOTs68-s6GxXQ.png" /><figcaption>Initial performance timeline</figcaption></figure><p>We seem to be loading more images than we need right now so let’s try our next optimisation.</p><h3>Lazy load images</h3><p>This is another advice that you hear often, what is not that common is that nowadays you can achieve this without any javascript by simply using the loading=&quot;lazy&quot; attribute in our images.</p><blockquote>The loading attribute support is pretty good and you can still selectively include a javascript-based lazy loader if you REALLY need IE/Safari support.</blockquote><p>After adding lazy loading support to our images our metrics look like this:</p><p><strong>FCP:</strong> 1.17s<br><strong>LCP:</strong> 1.98s (+24%)<br><strong>Page Size:</strong> 50.7kb (-25%)</p><p>Wait, why is our LCP time worse!? Page size went down which is not surprising since we’re loading one image less but let’s have a look at our timeline to understand the increased LCP time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*kGMlznEXdyZVKGISm4TrwQ.png" /><figcaption>Performance timeline after lazy loading</figcaption></figure><p>This is one gotcha that comes from lazy loading: <strong>browsers will decrease the priority of lazily loaded images </strong>which is great for images out of the viewport but not so much if it affects our LCP element.</p><p>The solution here is simple, <strong>avoid lazy loading images if they are above the fold</strong>. In this case we just need to remove the loading=&quot;lazy&quot; attribute from the first product image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*WSuBWu3pdWUTjiT8Q10xdg.png" /><figcaption>Performance timeline after selective lazy loading</figcaption></figure><p>By doing this we managed to make the browser load our LCP element sooner while still keeping the page size improvements:</p><p><strong>FCP:</strong> 1.17s<br><strong>LCP:</strong> 1.33s (-16%)<br><strong>Page Size:</strong> 50.7kb (-25%)</p><h3>Decode images asynchronously (maybe)</h3><p>Another not-so-known optimisation trick is to use the decode=&quot;async&quot; image attribute, this will tell the browser to decode the image asynchronously without blocking the main thread.</p><p>However for this demo it didn’t seem to make much difference, here’s how the timeline looks before and after the change:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*ujo6ywAJo1i7SRuMibT6PA.png" /><figcaption>Before decode=”async”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*QG4k9VYA2W-tycI3qmtmTA.png" /><figcaption>After decode=”async”</figcaption></figure><p>I didn’t notice any difference in the main thread, it still seems to be doing the same amount of work with and without the change even with the extra rasterizer thread that gets created. Maybe it’s because the demo doesn’t load that many images but I wanted to bring this up still just in case it helps anyone else, it doesn’t negatively impact our metrics so I chose to keep it for now.</p><h3>Use modern image formats</h3><p>So far I’ve been using JPEG’s in the demo to load product images but we can do much better. By converting images to WebP we can drastically decrease image size without any perceivable loss in quality so let’s try that first.</p><p><strong>FCP:</strong> 1.17s<br><strong>LCP:</strong> 1.26s (-20%)<br><strong>Page Size:</strong> 35kb (-48%)</p><p>Our page size is <strong>almost half</strong> of how it originally used to be and our LCP times keep getting better, however if you like living on the edge we can try a newer image format: <strong>AVIF</strong>.</p><blockquote>AVIF is modern image format based on the AV1 video format. AVIF generally has better compression than <a href="https://caniuse.com/#feat=webp">WebP</a>, JPEG, PNG and GIF and is designed to supersede them.</blockquote><p><strong>FCP:</strong> 1.17s<br><strong>LCP:</strong> 1.26s (-20%)<br><strong>Page Size:</strong> 24.2kb (-64%)</p><p>Our <strong>FCP</strong> and <strong>LCP</strong> times are still the same (maybe because of <a href="https://en.wikipedia.org/wiki/TCP_congestion_control#Slow_start">TCP slow start</a>?) but our page size is considerably smaller. The main downside of AVIF is that it’s not widely supported yet but we can use the &lt;picture&gt; element to display the correct image based on browser support.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*niE0uztqyWpHI_HRJfRHDw.png" /><figcaption>Prefer AVIF if not WEBP if not JPG</figcaption></figure><p>There’s another downside of WEBP and AVIF, I’ll show the JPG version and AVIF version side by side to see if you can spot the difference:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*L3LqtJmDPBG5F1GP4_j5CQ.gif" /><figcaption><strong>Left</strong>: JPEG version - <strong>Right</strong>: AVIF version</figcaption></figure><p>In case you didn’t see it, <strong>neither WEBP or AVIF support progressive loading</strong> so with JPEGs we get a lower quality preview of the image as it loads instead of it showing all at once.</p><p>If you want to achieve a similar effect you’ll need to display the lower quality version yourself, for the demo I chose to use <a href="https://github.com/axe312ger/sqip">SQIP</a> to display a lower quality SVG version of the main image applied as its background so it will get covered after the product image loads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*M56hMiWMlOPbt-qVQ0S0Mg.gif" /><figcaption>“Progressively” rendering AVIF images</figcaption></figure><p>From my testing this doesn’t affect the LCP times, I’m not sure if this is intentional or not but <strong>Chrome will still wait until the image is fully loaded to report that the largest contentful element has loaded</strong>, however it can help improve “perceived” performance which is also a good user experience.</p><p>Same as before, it doesn’t seem to negatively impact the metrics in the demo so I decided to keep it.</p><h3>HTTP2 Server Push</h3><p>So far we’ve been making improvements in the frontend to get out LCP times down but this for this last tip we’ll need to make a few tweaks to the way the server responds to HTTP requests.</p><p>Before doing anything let’s have a look at our biggest bottleneck so far:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*S1qa5SlV4hewFePF-L0Q2w.png" /><figcaption>Performance timeline analysis</figcaption></figure><p><strong>First:</strong> The HTML document needs to be downloaded and parsed, from top to bottom line by line so the browser knows what resources need to be downloaded next and with what priority. <strong>Then,</strong> it figures out that the CSS, logo and first product images need to be loaded first so it goes and fetches them but only after the first step is done.</p><p><strong>HTTP2 Server Push allows us to include hints to the browser about what resources to load as part of the response headers</strong>, so we can start loading them before the HTML has been parsed.</p><p>Modern web servers like nginx and Apache support this out of the box, the implementation varies slightly but generally they work by adding an extra Link header to the response header with a list of resources that look something like this:</p><pre>Link: &lt;/style.css&gt;; as=style; rel=preload, &lt;/image.jpg&gt;; as=image; rel=preload</pre><p>In a lot of cases this is not straightforward though, if the resources are the same you can get away by hardcoding them (eg: logos, common styles, etc) but if they change (like in the case of product images) you need a way of knowing exactly what images are going to be loaded depending on the page.</p><p>You may also end up pushing resources that are already cached by the browser forcing it to re-download them again and ironically hurting site performance.</p><p>I personally like <a href="https://www.cloudflare.com/website-optimization/http2/serverpush/">Cloudflare’s HTTP2 Server Push Service</a>, they help handle the extra complexity of browser cache but you are still required to send the resources via an extra Link header. I added this to the demo and the results are very impressive:</p><p><strong>FCP:</strong> 0.70s (-40%)<br><strong>LCP:</strong> 0.86s (-35%)<br><strong>Page Size:</strong> 24.2kb (-64%)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*sm4HpTqSXpHbRzhbxS_epQ.png" /><figcaption>Performance timeline analysis after HTTP2 Server Push</figcaption></figure><p>I preloaded the styles, logo and main product image with HTTP2 Server Push and as you can see they are loaded much sooner (even our <strong>FCP</strong> times were cut almost in half).</p><p>Sometimes it’s hard to appreciate numbers by themselves so for perspective here’s a comparison of all the optimisations done until now as a filmstrip view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SpsFzYZ11uAyaJNxyurIBw.jpeg" /><figcaption>Filmstrip view of optimisations</figcaption></figure><h3>Key takeaways</h3><ol><li>At the very minimum lazy load images with appropriate sizes and formats.</li><li>HTTP2 Server Push can improve FCP / LCP times but implementation can be tricky.</li><li>Measure and profile EVERY change you make, you can’t improve what you don’t measure.</li></ol><p>I hope these tips help you improve your website performance and Lighthouse scores, let me know if there’s anything missing that you’ve used to deal with FCP / LCP times. 👋🏽</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e9866087973" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/optimising-images-for-better-lcp-web-vitals-scores-7e9866087973">Optimising images for better LCP web vitals scores</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript sliders will kill your website performance]]></title>
            <link>https://itnext.io/javascript-sliders-will-kill-your-website-performance-5e4925570e2b?source=rss-a2ed5b4c8a17------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e4925570e2b</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[slider]]></category>
            <dc:creator><![CDATA[Javier]]></dc:creator>
            <pubDate>Mon, 16 Nov 2020 12:33:06 GMT</pubDate>
            <atom:updated>2020-11-22T21:50:44.455Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zhNjsyY9Uo8Z88Ukw2p6Xg.jpeg" /><figcaption>Photo by Vincentas Liskauskas</figcaption></figure><p>Sliders (or carousels) are some of the most common elements in almost any website these days, regardless of how you feel about them they can offer a convenient way of displaying information specially when screen size is limited.</p><p>In e-commerce websites use cases range from displaying featured products, banners, promotions, product galleries, you name it! There’s no shortage of these bad boys in the wild even though their effectiveness is <a href="https://thegood.com/insights/ecommerce-image-carousels/">a bit controversial</a> it’s one of those things users are used to seeing so it provides a low-friction experience for most people.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tcw9CRZwqd6KCKC7WpY5ng.gif" /><figcaption>Style feed in <a href="https://www.asos.com/">asos.com</a> using a slider</figcaption></figure><p>Luckily for us frontend developers there are hundreds of Javascript-based sliders out there to choose from, unfortunately most of them share the same draw back: <strong>they are terrible for performance</strong>, and believe me when I say it because I’ve used all of them, every single one of them¹.</p><h3>They can’t all be that bad!</h3><p>Well time to run some tests, let’s create a very simple slider implementation to display a list of product images, almost every e-commerce shop has one of these in some form or another so even though the looks will vary it’s a common enough to use as an example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*0zuoYecylTeM2OKZVoPKrw.gif" /><figcaption>Super simple product gallery slider</figcaption></figure><p>As you can see it’s very simple, only one slide at a time, no arrows, no navigation indicators or anything fancy. All I’m doing is displaying part of the next or previous image to provide some feedback to the user and let them know they can swipe left and right to see more content.</p><h3>The top contenders</h3><p>I didn’t want to spend hours testing every single javascript slider out there so I picked the top 5 that have worked best for me over the years:</p><ol><li><a href="https://kenwheeler.github.io/slick/">Slick Slider</a></li><li><a href="https://owlcarousel2.github.io/OwlCarousel2/">Owl Carousel</a></li><li><a href="https://flickity.metafizzy.co/">Flickity</a></li><li><a href="https://keen-slider.io/">Keen-slider</a></li><li><a href="https://nickpiscitelli.github.io/Glider.js/">Glider.js</a> <em>(kind of, more on this later…)</em></li></ol><p>All of these sliders have something important in common, they provide the bare minimum CSS styles to make them work, any kind of customisation on top of that is up to you. This is a key feature for me because I tend to customise sliders heavily anyways so the least I have to override the better, also you don’t want to include a bunch of CSS on top of the extra JS you’ll need for your slider.</p><p>I won’t go into many implementation details but if you want to know more feel free to check each library’s documentation, they’re all pretty good.</p><h3>Slick</h3><p>Slick has been my top choice when it comes to implementing feature-rich sliders on the web, it has almost every feature under the sun, a very simple API and animations are very smooth as it supports CSS transforms out of the box, so let’s give that a go.</p><p>All we need to do is to include the library with a script tag, the required CSS and initialise it like so:</p><pre>$(function () {<br>    $(&#39;.js-slider&#39;).slick({<br>        centerMode: true,<br>        centerPadding: &#39;15px&#39;,<br>        arrows: false,<br>        infinite: false,<br>    });<br>})</pre><p>Can’t get any easier than that, let’s see how our resources look like:</p><ul><li><strong>JS</strong>: 126 Kb</li><li><strong>CSS</strong>: 4.9 Kb</li></ul><p>Right away we can see one of the biggest downsides, slick by itself is pretty big (<strong>42.4 kb</strong> minified) but we also need jQuery on top of that, this is not a big issue if you’re using jQuery already but the size of the library itself is something to consider.</p><p>What about core web vital metrics? For this I will be testing on a simulated <strong>Fast 3G</strong> connection and using <strong>4x CPU Slowdown </strong>for all tests:</p><ul><li><strong>Total Blocking Time (TBT)</strong>: 0ms</li><li><strong>First Contentful Paint (FCP)</strong>: 1989ms</li><li><strong>Largest Contentful Paint (LCP)</strong>: 2789ms</li><li><strong>Content Layout Shift (CLS)</strong>: 0.1344</li><li><strong>Time to Interactive (TTI)</strong>: 2939ms</li></ul><p>Straight away we can see the impact of all that JS in our test, it takes almost <strong>2 seconds</strong> to see anything meaningful on the screen and almost <strong>3 seconds</strong> for it to be interactive. There’s also some layout shift while the slider loads:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*6ApOC_G4Nr2R6RqqLfDHQg.gif" /><figcaption>Slick slider layout shift</figcaption></figure><p>This is pretty easy to fix with just a few lines of CSS, we just need to make sure our images have the same styles before and after the scripts are parsed and executed, in this case all it takes is the following:</p><pre>.gallery &gt; .slide:not(:first-child) {<br>    display: none;<br>}</pre><pre>.gallery &gt; .slide:first-child {<br>    padding: 0 20px;<br>}</pre><p>This way we hide everything but the first slide in our carousel and add the padding on the sides that Slick will add after it loads. Slick will add extra wrapping elements to our slides so the immediate children selector (&gt;) will make the styles only apply before it loads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*TxiY1RUXYwhmVK-qCo9d5w.gif" /><figcaption>Slick slider with improved CLS</figcaption></figure><p>Excellent, no layout shift and by hiding the extra slides the browser will assign a lower priority to those images which should improve our <strong>FCP</strong> metrics:</p><ul><li><strong>Total Blocking Time (TBT)</strong>: 0ms</li><li><strong>First Contentful Paint (FCP)</strong>: 1356ms <em>(31% decrease)</em></li><li><strong>Largest Contentful Paint (LCP)</strong>: 2568ms <em>(8% decrease)</em></li><li><strong>Content Layout Shift (CLS)</strong>: 0 <em>(100% decrease)</em></li><li><strong>Time to Interactive (TTI)</strong>: 2746ms <em>(6% decrease)</em></li></ul><p>These are very good improvements but they don’t look that great when you run Google Lighthouse:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*mNFmpCaYx3xlMUnqEaQziA.png" /><figcaption>Google lighthouse score using Slick</figcaption></figure><blockquote>All it takes is <strong>jQuery</strong> and <strong>Slick</strong> to knock <strong>9 points off</strong> our Google Lighthouse Mobile score on a super basic page with barely any HTML or CSS.</blockquote><p>Think about it, most websites (specially e-commerce sites) have way more stuff than this, so when you put it into perspective you start to realise there’s no chance to get to that sweet score of <strong>100 </strong>without trimming some fat.</p><p>But WHY!? You may ask, well let’s profile our page load see how it looks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*7nyxOV2Pv-BP1fUwjJkW9A.png" /><figcaption>Slick page load performance profile</figcaption></figure><p>The Chrome DevTools profiler can be scary but generally what you care about is that lines should be short and the stack trace should be shallow, longer lines mean tasks are taking too long and deeper stack traces mean that functions keep calling other functions which can make tasks slower. Keep in mind Google only gives us <a href="https://web.dev/rail/#goals-and-guidelines">up to 100ms for each task</a> before they start shouting at us so we need to make the most out of it.</p><p>We also see a lot of time spent <strong>Scripting </strong>(JS execution / Yellow) and on <strong>Layout</strong> (Putting stuff on the screen / Purple), most likely because Slick needs to run a lot of calculations to know where to put slides on the screen and how to arrange them.</p><p>Let’s move on for now.</p><h3>Owl Carousel</h3><p>Another crowd favourite, Owl Carousel has a similar set of features than Slick but it’s a bit smaller which is a good thing as far as web performance goes, so let’s have a look.</p><p>Same as before we just need to add some CSS, JS script tags and initialise it like so:</p><pre>$(function () {<br>    $(&#39;.js-slider&#39;).owlCarousel({<br>        center: true,<br>        stagePadding: 15<br>    });<br>});</pre><p>We also need to add some classes to our HTML unless we customise the initialisation options. Now let’s check our main resources now:</p><ul><li><strong>JS</strong>: 117 Kb <em>(7% decrease)</em></li><li><strong>CSS</strong>: 6.8 Kb <em>(38% increase)</em></li></ul><p>So we have less JS but more CSS compared to Slick, this might look like a bad trade but keep in mind not all bytes are treated equally, the <a href="https://v8.dev/blog/cost-of-javascript-2019">cost of scripts is more dominant</a> than any other resource for the browser so in a lot of cases reducing javascript at the cost of styles or images will yield better performance results as seen below:</p><ul><li><strong>Total Blocking Time (TBT)</strong>: 0ms</li><li><strong>First Contentful Paint (FCP)</strong>: 1324ms <em>(33% decrease)</em></li><li><strong>Largest Contentful Paint (LCP)</strong>: 2545ms <em>(8% decrease)</em></li><li><strong>Content Layout Shift (CLS)</strong>: 0.1295 <em>(3% decrease)</em></li><li><strong>Time to Interactive (TTI)</strong>: 2376ms <em>(19% decrease)</em></li></ul><p>These results are better compared to Slick’s first implementation but we still have some layout shift issues:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*VHNOWMkwhQm5wEu3GSbjUw.gif" /><figcaption>Owl carousel layout shift</figcaption></figure><p>For some reason Owl Carousel decides to hide the slider completely until it finishes loading. Just like we need before we can fix this with just a few lines of CSS and we can end up with much better results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*CKcNvXSkW-eD1LCYT_uCfw.gif" /><figcaption>Owl Carousel with improved CLS</figcaption></figure><p>Now let’s look at our metrics again:</p><ul><li><strong>Total Blocking Time (TBT)</strong>: 0ms</li><li><strong>First Contentful Paint (FCP)</strong>: 1330ms <em>(2% decrease)</em></li><li><strong>Largest Contentful Paint (LCP)</strong>: 2396ms <em>(6% decrease)</em></li><li><strong>Content Layout Shift (CLS)</strong>: 0</li><li><strong>Time to Interactive (TTI)</strong>: 2357ms <em>(14% decrease)</em></li></ul><p>Much better compared to our Slick slider version with improved <strong>CLS </strong>specially when it comes to <strong>TTI</strong>. The performance report is very similar to Slick’s so nothing new to see here.</p><h3>Flickity</h3><p>Flickity and Owl Carousel both have very similar results, during my tests the metrics only varied slightly so I don’t think it’s worth going into much detail about it.</p><p>Moving on…</p><h3>Keen Slider</h3><p>Keen Slider is a newer alternative to most popular sliders on the web, it doesn’t provide a massive set of features but it’s very lightweight and has no dependencies which makes it a perfect fit for our simple product gallery carousel.</p><p>Let’s see how it compares in terms of resources:</p><ul><li><strong>JS</strong>: 10.3 Kb <em>(91% decrease)</em></li><li><strong>CSS</strong>: 3.7 Kb <em>(24% decrease)</em></li></ul><p>That’s just <strong>a tenth</strong> of Owl Carousel’s JS and about <strong>three quarters </strong>of<strong> </strong>Slick’s CSS, these savings show clearly in our web vital metrics:</p><ul><li><strong>Total Blocking Time (TBT)</strong>: 0ms</li><li><strong>First Contentful Paint (FCP)</strong>: 1275ms <em>(3% decrease)</em></li><li><strong>Largest Contentful Paint (LCP)</strong>: 1667ms <em>(34% decrease)</em></li><li><strong>Content Layout Shift (CLS)</strong>: 0.2456 <em>(89% increase)</em></li><li><strong>Time to Interactive (TTI)</strong>: 1740ms <em>(26% decrease)</em></li></ul><p>Pretty significant improvements considering the end result is pretty much the same:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*MIYGrM6Jjcd4fj13z60Cig.gif" /><figcaption>Keen Slider layout shift</figcaption></figure><p>Like our other examples we have some layout shift going on but it’s very simple to fix with some CSS and the end results are even better:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*wgXdrQBdmrPRHF5Hp_kAuw.gif" /><figcaption>Keen Slider with improved CLS</figcaption></figure><p>Most metrics are identical after this change but without any layout shift we’re finally achieving an acceptable user experience.</p><p>We can run a quick profile on our page load to see where the performance gains are coming from, here’s a summary of our longest running task which is initialising the slider:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*Ui-5v2fXDoj5Ec6AeRScyA.png" /><figcaption>Keen Slider page load performance profile</figcaption></figure><p>As you can see there’s barely any work being done, most of the time is spent <strong>scripting </strong>and there’s next to none <strong>layout</strong> work.</p><blockquote>It takes Keen Slider 2.73ms to render our slider, in comparison Slick takes <strong>125.23ms</strong> to do the same.</blockquote><h3><strong>Glider.js</strong></h3><p>Glider takes a very different approach to the options we’ve seen so far, it’s still a very lightweight library but it’s main difference comes from using the CSS Scroll behaviour instead of CSS transforms to animate slide transitions. Think of it as a div with overflow: auto with some JS sprinkled on top to allow for arrows, navigation and other common slider functionality.</p><p>Because of this it provides even fewer options than Keen Slider so you won’t be able to do any fancy autoscroll, infinite slides, custom easing and whatnot, which makes me wonder: <strong>what if we implement the gallery slider with CSS only and get rid of the JS altogether?</strong></p><h3>CSS-only approach</h3><p>So far we’ve used Javascript to render our simple product image gallery if we’re willing to make some concessions we can cut down our scripts down to zero.</p><p>We can use a couple CSS features that will make building our slider a breeze: <strong>CSS Grid</strong> to handle the layout and <strong>CSS Scroll Snap</strong> to control the scrolling experience.</p><p>Surprisingly all it takes is the following lines of CSS to achieve virtually the same results we’ve had with JS so far:</p><pre>.gallery {<br>    display: grid;<br>    grid-gap: 10px;<br>    grid-auto-flow: column;<br>    grid-auto-columns: calc(100% - 20px);<br>    padding-left: 20px;<br>    scroll-snap-type: x mandatory;<br>    overflow: auto;<br>}</pre><pre>.slide {<br>    scroll-snap-align: center;<br>}</pre><pre>.slide:last-child {<br>    position: relative;<br>}</pre><pre>.slide:last-child::after {<br>    content: &#39;&#39;;<br>    position: absolute;<br>    top: 0;<br>    width: 20px;<br>    height: 100%;<br>}</pre><p>With <strong>CSS Grid</strong> we can position our images in a single row and size them so the next and previous image are partially revealed, with overflow: auto we enable horizontal scrolling and with <strong>CSS Scroll Snap</strong> we control that images snap to the centre so a full image is always in view.</p><p>The :last-child trick is to allow some space at the end of the slider because browsers won’t add extra scroll space to the end of a scrolling container even with extra padding so it prevents images from reaching the edge of the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*im7dqbY1IWj59yWmswyV2g.gif" /><figcaption>CSS-only gallery slider</figcaption></figure><p>The end result is very similar to what we are going for with some minor drawbacks:</p><ul><li><strong>Horizontal scrollbar</strong>: which you could hide with CSS but I don’t mind it because it gives a non-intrusive form of extra feedback.</li><li><strong>No “rubber band” effect when trying to scroll past the end of the last slide:</strong> I’m willing to live without this.</li></ul><p>On top of this you get some extra <strong>accessibility features</strong> with no extra effort, some of the JS sliders that Slick provide some degree of keyboard navigation but in my experience it’s nowhere near as good as this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*XYf4x6oOR4rQqcifIQ-npw.gif" /><figcaption>CSS-only gallery keyboard navigation</figcaption></figure><p>And of course the final performance metrics are much better than its JS-based counterparts:</p><ul><li><strong>JS</strong>: 0 Kb <em>(100% decrease)</em></li><li><strong>CSS</strong>: 3.5 Kb <em>(5% decrease)</em></li><li><strong>Total Blocking Time (TBT)</strong>: 0ms</li><li><strong>First Contentful Paint (FCP)</strong>: 1284ms</li><li><strong>Largest Contentful Paint (LCP)</strong>: 1380ms <em>(17% decrease)</em></li><li><strong>Content Layout Shift (CLS)</strong>: 0</li><li><strong>Time to Interactive (TTI)</strong>: 1358ms <em>(22% decrease)</em></li></ul><p>What’s interesting here is that the time it takes to render content on the screen remains consistent but as soon as our first image loads that’s it, the page is fully interactive. No need to wait to download, parse and execute expensive JS calculations and we can finally say hi to that elusive score of <strong>100.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*ZF_cOaVGGWO8L62jDmuT_Q.png" /><figcaption>Lighthouse score with CSS-only slider</figcaption></figure><p>If you want to play around with the code here’s a working example in Codepen: <a href="https://codepen.io/javiervd/pen/qBNgPjN">https://codepen.io/javiervd/pen/qBNgPjN</a> 👨🏾‍💻</p><h3>Summary</h3><p>It’s important to know that this is a very simple implementation of a slider, if you need more functionality this will obviously not be enough but the main takeaways from this exercise is to ask yourself:</p><ol><li><strong>Do you really need a slider? </strong>If not save yourself the extra code and display your content in a different way (eg: grid, blocks, etc)</li><li><strong>If you do, can you get away with going CSS-only?</strong> Do you really need that slider to autoscroll every 5 seconds? (It’s annoying BTW)</li><li><strong>If not, can you use keen slider or Glider.js? </strong>They will get you a long way without taking a massive performance hit.</li></ol><p>Sliders can be great and all but it’s not worth wasting your performance budget over them specially when it can be used on harder to replace libraries like state managers or frontend frameworks.</p><p>[1]: I may not have used every single JS slider out there.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e4925570e2b" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/javascript-sliders-will-kill-your-website-performance-5e4925570e2b">Javascript sliders will kill your website performance</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to improve Magento 2 Page Speed Insights Score?]]></title>
            <link>https://medium.com/@jahvi/how-to-improve-magento-2-page-speed-insights-score-bb37e8946192?source=rss-a2ed5b4c8a17------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb37e8946192</guid>
            <category><![CDATA[magento-2]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[magento]]></category>
            <category><![CDATA[pagespeed-insights]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Javier]]></dc:creator>
            <pubDate>Thu, 09 Jan 2020 13:01:01 GMT</pubDate>
            <atom:updated>2020-01-09T13:01:01.872Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KdTkB29_xHepRGepTrBR8w.jpeg" /><figcaption>Photo by Marc-Olivier Jodoin</figcaption></figure><p>As much as I like working with Magento 2 I have to admit it’s never been known for its blazing performance, page loading speeds in both frontend and backend have been consistently slower than its own 1.9 version and that’s been a problem most Magento developers have had to deal with in some way or another.</p><p>Don’t get me wrong, there are a lot of changes Magento’s done to improve development experience: using composer, the plugin system, dependency injection, just to name a few, but page loading speeds (specially on the frontend) have suffered because the frontend stack that Magento decided to go with hasn’t scaled very well and it’s so tied to the core that making drastic changes to it involves a lot of work.</p><p>That’s why we’ve seen a push for PWA solutions like <a href="https://www.vuestorefront.io/">Vue Storefront</a> or Magento’s own <a href="https://github.com/magento/pwa-studio">PWA Studio</a> to bring a more modern approach to the e-commerce experience but what can should we do with all the Magento 2 stores running now? Should we rewrite them all from scratch as a PWA?</p><p>Well… Yes! If that’s an option, however there are some things we can do to improve page loading speeds using the current Magento 2 stack that I don’t see being discussed that often.</p><p>I’ll be using <strong>Google’s Page Speed Insights </strong>score to measure the impact of these improvements because it’s “the standard” for these sort of things these days and Magento is not known to score very well out of the box but first we need to understand how the score works so we know what we should be focusing on.</p><h3>Understanding the Page Speed Score</h3><p>Google’s Page Speed Insights performance score is a summary of 6 main metrics:</p><ul><li><strong>First Contentful Paint:</strong> marks the time at which the first text or image is painted.</li><li><strong>First Meaningful Paint:</strong> measures when the primary content of a page is visible.</li><li><strong>Speed Index:</strong> shows how quickly the contents of a page are visibly populated.</li><li><strong>Time to Interactive:</strong> the amount of time it takes for the page to become fully interactive.</li><li><strong>First CPU Idle:</strong> marks the first time at which the page’s main thread is quiet enough to handle input.</li><li><strong>Max Potential First Input Delay:</strong> The maximum potential First Input Delay that your users could experience is the duration, in milliseconds, of the longest task.</li></ul><p>These scores however are not treated equally, Google has a lot of data about how people in the real works use the web in their <a href="https://developers.google.com/web/tools/chrome-user-experience-report">Chrome User Experience Report</a> so they can recommend best practices based on the analysis of millions of users across millions of websites.</p><p>Here’s <a href="https://docs.google.com/spreadsheets/d/1up5rxd4EMCoMaxH8cppcK1x76n6HLx0e7jxb0e0FXvc/edit#gid=0">how the metrics are scored</a> as of December 2019:</p><ul><li><strong>Time to Interactive — 33.3%</strong></li><li><strong>Speed Index — 26.7%</strong></li><li><strong>First Contentful Paint — 20.0%</strong></li><li><strong>First CPU Idle — 13.3%</strong></li><li><strong>First Meaningful Paint — 6.7%</strong></li><li><strong>Max Potential First Input Delay — 0%</strong></li></ul><p>Based on this we can conclude that not only we have to display content on the screen quickly, we also need to <em>make sure the content can be interacted with quickly, </em>that means: as soon as something can be seen users should be able to click it, tap it, scroll it, etc., and the page should respond accordingly.</p><p>Let’s see how this all looks in a base installation of Magento 2.2.10 (I’ll come back to the version number later) using the Luma theme and sample data:</p><blockquote>For convenience, I’ll be using Chrome’s built-in Lighthouse audits to measure performance.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_91_oBcEcDlP9WfepGVOgA.png" /><figcaption>Magento 2.2.10 performance score, Slow 4G — 4x CPU Slowdown (Homepage)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sJIkAWg5xkpCI9pXaaQn2Q.png" /><figcaption>191 out of 227 requests are JS files— 662 KB gzipped (Homepage)</figcaption></figure><p>As you can see we get decent FCP and FMP times but everything else is lacking. This makes sense when we understand that Magento adds hundreds of scripts on each page load and they are included for the most part using RequireJS, that means they get loaded <strong>in sequence not in parallel</strong> so the browser has to wait a while until all of them have been downloaded, parsed, compiled and executed.</p><p>This is made worse by the fact that when it comes to the web not all bytes are equal, browsers need to work harder to process 100kb of JS than the same amount in CSS, images, fonts or any other asset. I won’t go into too much details but if you want to know more have a read at Addy Osmani’s <a href="https://v8.dev/blog/cost-of-javascript-2019">The cost of JavaScript in 2019</a>.</p><h3>Setting up our goal</h3><p>So now we know that Google’s Page Speed score gives priority to sites that can be interacted with quickly, however there are so many scripts included by default in Magento 2 that no matter how minified, merged or bundled they are they still need a lot of time to load.</p><p>Instead of coming up with some fancy new way of optimising all this code, I think we should try to:</p><blockquote>Remove as many scripts as possible…</blockquote><p>And I don’t mean getting rid of a couple JS files here and there, I mean going for a <em>deep clean </em>and see how far that takes us.</p><blockquote>I won’t be performing any kind of server-side optimisations or anything else in the frontend other than removing JS for now, because I want to measure the impact that just JavaScript alone is having on our website.</blockquote><h3>Let the purge begin</h3><p>Let’s start with the easy stuff, we can disable all the modules that we know we won’t use in our Magento 2 website. This might not remove any JS files since not all modules have frontend assets however it will potentially reduce the server response time which will improve all the Page Speed Score metrics proportionally.</p><ul><li>Are you not using MSI? Kill it ☠️</li><li>Don’t care about swatches? Kill it ☠️</li><li>Amazon Payments? Kill it ☠️</li><li>Klarna? Kill it ☠️</li><li>Temando Shipping? WTF is that!? Bye ☠️</li></ul><p>Worst case scenario it will declutter our admin area and make DI compilation quicker so there aren’t any downsides that I can think of, just make sure not to disable modules that are being dependent on.</p><p>Integer_net has a nice article on how to <a href="https://www.integer-net.com/make-magento-2-small-again/">remove unused core modules</a> with composer but I found that just disabling them works well enough.</p><h3>Upgrade to Magento ≥ 2.3.3</h3><p>Earlier in the article I ran the initial Page Speed measurements on an “old” 2.2.10 version of Magento on purpose to showcase one of the main features introduced in 2.3.3.</p><p>Earlier versions of Magento used to include the whole jQuery UI library even though they only used some of its components. Starting on 2.3.3 jQuery UI has been split into smaller parts so only the code that’s necessary gets loaded when it’s needed, this gives us some performance benefits for free.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Otqfkg5xMrfhglzrrhYbg.png" /><figcaption>Magento 2.3.3 performance score.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6iAZw8lsZlSFFW4QL1joGA.png" /><figcaption>169 out of 206 requests — 607 KB gzipped.</figcaption></figure><p>As you can see we managed to <strong>improve our score by 10%</strong>, decreased our JS request size by ~10% and JS request count by ~10%. Nothing extraordinary but keep in mind we haven’t written a single line of code yet.</p><p>Using 2.3.3 comes with its own set of issues but if you can afford the upgrade it can give you instant performance wins.</p><h3>Removing unused scripts</h3><p>Now comes the fun part, out of all those 169 JS files how many of those is our website actually using?</p><p>We need to find out what files are not being used and delete them to oblivion, this sounds simple but it’s can be very tricky because:</p><ol><li>Just because the script is not used somewhere it doesn’t mean it’s not used somewhere else.</li><li>Scripts can have very obscure dependencies, even not so obvious ones.</li></ol><p>One of the easiest ways I’ve found to spot unused code is by using <a href="https://developers.google.com/web/tools/chrome-devtools/coverage">Chrome’s Code Coverage Report</a>, so try switching it on, reload the page and interact with it for a while to see how much of the code it’s actually being used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8a5qDJn_jfahN0Hhc1JyGA.png" /><figcaption>Only 43% of JS code being used.</figcaption></figure><p>Here we can see some obvious and not so obvious suspects just by looking at the “Unused Bytes” column, keep in mind that even if they seem like they’re being used (30–40% usage) there’s a good chance that it’s coming from the initialisation code that runs when the file is included not from actual usage on the page so make sure to go into all of them and review the report.</p><p>I’ll go through the files I ended up removing with my reasoning behind it but don’t follow my advise blindly as it might not apply to your project in the same way:</p><ul><li><strong>range.js: </strong>Looks like some sort of range slider, maybe used as a price slider somewhere but not even the layered navigation uses it by default, so bye! ☠️</li><li><strong>colorpicker.js: </strong>I can’t remember the last time I used a colorpicker in an e-commerce site. ☠️</li><li><strong>datepicker.js: </strong>Same as above, I can think of more use cases for this but definetly not needed everywhere. ☠️</li><li><strong>tooltip.js: </strong>This is used to render some information tooltips around the site, we use CSS for this functionality so no need. ☠️</li><li><strong>polyfill.js: </strong>Looks like a polyfill for localStorage and sessionStorage for older browsers, this is also useful in some modern browsers (like Safari on iOS) where there’s no localStorage when using Incognito / Privacy Mode so it falls back to using cookies but in our case we don’t care about this feature. ☠</li><li><strong>decorate.js: </strong>Used to add classes to lists, presumably for styling (first, odd, even, last). Maybe a remnant of the Magento 1 days when the CSS :nth-child selector wasn’t as widely supported. ☠️</li></ul><p>There are some files that need more digging, for example I could see some <strong>draggable.js </strong>and <strong>resizable.js</strong> files being loaded but I couldn’t think of anywhere where I would care about these features. Luckily you can use Chrome to hunt down these dependencies:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xMPjqQs7ERD3B6CaZ0VhNA.png" /><figcaption>Chrome search feature</figcaption></figure><p>Using this feature you can search within loaded assets and see which files are trying to load unwanted dependencies. In this case it was used by the <strong>dialog.js </strong>file to allow you to resize and drag the modal windows around (eg: “remove from minicart” modals), a very core e-commerce feature I know but something I’m willing to live without.</p><h3>Stripping down the minicart</h3><p>While I was looking at the minicart component I realised there’s a lot of stuff there I wasn’t very emotionally attached to:</p><ul><li><strong>confirm.js </strong>and <strong>alert.js: </strong>Only used when you want to confirm a removal from cart or display an error. We don’t mind removing items from the cart without confirmation and for errors we can display them using the regular Magento Ui messages. ☠️</li><li><strong>effects-fade </strong>and <strong>effects.js:</strong> Used to fade out items when removed from the cart, again not that bothered to lose that, if needed we can have it cheaper with a timeout + CSS transitions. ☠️</li><li><strong>authentication-popup.js: </strong>Used to display a popup if you require login to checkout, case by case dependant but we can get rid of it for now, if needed maybe a redirect with a message might be enough. ☠️</li></ul><p>We could argue that by removing this code we’re left with a “poorer” user experience but when making decisions like this try to take this line of though:</p><blockquote>Is the user going to be bothered by items not fading out when removed from the cart? Maybe not. Will they be bothered by the extra second it takes to load every single page because of this code? Probably.</blockquote><h3>Misc template changes</h3><p>️Some scripts might need to be removed from .phtml template files, for example:</p><ul><li><strong>menu.js: </strong>We usually use CSS for any interactivity with the menu and any JS we use will be way less than what’s included by default. ☠️</li><li><strong>form-mini.js: </strong>We rarely use the default Magento search so no need to include this to handle autocompletion. ☠️</li></ul><blockquote>Some third-party modules are known for extending this file so make sure it’s not being used.</blockquote><p>There are some less than obvious ones as well:</p><ul><li><strong>swatches-render.js: </strong>Even though we do use swatches occasionally we rarely render them on product lists so we don’t need this. If you do, be ready to deal with other DB performance issues as a result. ☠</li><li><strong>t️ranslate-inline.js: </strong>Used to render the UI to translate strings directly on the frontend, we never use this as all translations are done in the code level. ☠️</li></ul><h3>Replacing libraries</h3><p>So far we’ve been removing unused script files but we can also replace some of the biggest libraries with some alternatives that will make the total request size smaller.</p><p>To help with this you can use <a href="https://bundlephobia.com/">Bundlephobia</a> to have an idea of the impact a given library will have on your site and even get some recommendations on alternatives you can use to replace it, eg:</p><ul><li><strong>moment.js: </strong>Luckily Magento 2 doesn’t come bundled with the whole moment.js library but it’s still quite big (~20KB). As far as I could see it’s only used for some logging functionality and date validations so we can replace it with something like <a href="https://github.com/iamkun/dayjs">dayjs</a> (~2KB) and remove ~95% of that code. ☠️</li><li><strong>jquery.js: </strong>This is a bit scarier because jQuery is used EVERYWHERE but upgrading to jQuery 2.2.4 will reduce the library size by ~10%. This major version only dropped support for older browsers while keeping backwards compatibility so in theory (and in my limited testing) it should still work without major issues. ☠️</li><li><strong>underscore.js: </strong>I didn’t actually change this one but I still thought it would be worth mentioning. In theory this library could get the same treatment as jQuery UI and split it into separate components (using something like <a href="https://github.com/lodash/lodash">lodash</a>) since only ~40% is used at a time but it will require a lot of work and I don’t know if it’s worth for the sake of saving 5–6KBs. ⚠️</li></ul><h3>Going the extra mile</h3><p>We’ve been focusing on JS since by know we know that’s what the browser struggles with the most, but we’re on a warpath here so we might as well get rid of other assets while we’re at it, eg:</p><ul><li><strong>CSS:</strong> For this I don’t mean performing any kind of Critical Path optimisations, I mean removing styles we won’t use. Since we already removed the date-picker stuff it makes sense to get rid of the <strong>calendar.css</strong> styles as well, etc. ☠️</li><li><strong>Fonts: </strong>Sounds be obvious but let’s get rid of all the custom fonts and variations we’re not using. ☠️</li><li><strong>Icons: </strong>We use SVG icons for these so we can get rid of the Luma/Blank icon font.</li></ul><h3>Measuring again</h3><p>Let’s see how we look after doing all that work:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0C03l4YBsKfq5rrg1wLpyg.png" /><figcaption>Post script removal performance score.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e7UBXxKYzs4Q7T9RPmdNHQ.png" /><figcaption>123 out of 153 requests — 433 KB gzipped.</figcaption></figure><p>Still nothing formidable however if we compare it with our initial numbers we can see a:</p><ul><li><strong>42% increase in Page Speed Score</strong>. 🎉</li><li><strong>42% decrease in request count.</strong> 🎉</li><li><strong>42% decrease in JS bundle size. </strong>🎉</li></ul><p>You can probably spot a trend now, <strong>removing code proportionally benefits our Page Speed Score</strong>. Keep in mind we haven’t <em>written</em> any code, just removed or replaced so that’s code that we’ll never have to worry about maintaining, updating, patch or concern if it becomes vulnerable.</p><p>On top of that I’ve been running these audits on a less than ideal environment by using:</p><ul><li>Local development environment.</li><li>Developer mode.</li><li>No composer optimisations.</li><li>No minification or caching.</li><li>No image lazy loading.</li><li>No CDN.</li></ul><p>So other than removing JS I haven’t focused on any of the more well known “tricks” to improve frontend performance, in fact the Audits show a lot of room for improvement:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z-OVBkgDv_pBJ9Ju8w09HA.png" /><figcaption>Lighthouse opportunities</figcaption></figure><p>So I went ahead and took care of most of these, the only one I didn’t bother with for now was “Removing Unused CSS” and “Optimising for the Critical Path” because:</p><ol><li>It’s more time consuming than removing JS.</li><li>In my limited testing it hasn’t improved load times that much. I think people underestimate how good browsers are at painting pixels on the screen.</li></ol><p>However I did:</p><ul><li>Enable JS, CSS and HTML minification.</li><li>Add our own image lazy loading extension.</li><li>Switch Magento to production mode and optimise composer autoloader.</li></ul><p>So let’s see, how are we looking?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aWmRK7mRqpC7Ynb4iKLCZg.png" /><figcaption>Post script removal + minification + lazy loading + composer optimisations.</figcaption></figure><p>Much better now, yet there’s still more we can do…</p><h3>Bundling Magento 2 JavaScript</h3><p>Even though we’ve removed a lot of JS code we’re still loading hundreds of files per request, which wouldn’t be a massive issue if they were prefetched and loaded in parallel thanks to HTTP/2, but they’re not…</p><p>I don’t want to go into details as to why that’s the case because it will make the article too long but files are being loaded in sequence thanks to the way RequireJS works and that’s why our Time to Interactive is still high. If you want to know more about this Willem Wigman from integer_net has written a detailed article about <a href="https://www.integer-net.com/ultimate-guide-magento-2-javascript-bundling/">Magento 2 JavaScript Bundling</a>.</p><p>Luckily there are tools that can be incorporated in our deployment process that can help optimise JS beyond a simple merge and minification like:</p><ul><li><a href="https://github.com/magento/baler/">Baler</a></li><li><a href="https://github.com/magento/m2-devtools">Magento 2 DevTools</a></li></ul><p>The article I linked to above describes in more detail how to use each of them, I’ll be using the “Magento 2 DevTools” approach with the changes Willem recommended in his article because, even though these are no longer supported, I’ve got the best results with them but “Baler” looks very promising so far.</p><p>So after optimising our JS bundles with the “Magento 2 DevTools” we’re looking like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iwkjceIMoZRZBywPFQz07w.png" /><figcaption>Final optimisation score with JS bundling.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QxJDqJAbyr5WbrF1ME3vhQ.png" /><figcaption>4 out of 14 requests — 148 KB gzipped.</figcaption></figure><p>So close, yet so far… But it’s a very good score nevertheless, even one that some PWAs struggle to accomplish these days.</p><p>On top of optimising JS bundles I made sure to add &lt;link rel=&quot;preload&quot; href=&quot;...&quot; as=&quot;script&quot;&gt; in the HTML&lt;head&gt; to make sure the scripts are loaded as soon as possible. This increases the FCP and FMP times a bit but reduces TTI by quite a lot which is the most important metric.</p><h3>Closing thoughts</h3><p>I’m sure there are ways to keep improving this score even more, I’ll keep working on this to get it closer to that sweet “100” but there are many areas of improvement. So for we only focused on JS and although it’s the biggest piece of the puzzle there are other ones that could use more attention (CSS, images, fonts, HTML).</p><p>Also, these kinds of optimisations are not the ones you only worry about at the end of the project, I’d argue that it might be to late then. You need to keep them in the back of your head every time you work on a new feature, perform and upgrade or install any new extension. Try to keep the amount of code as small as possible, the code that’s more optimised is the one that’s not there in the first place!</p><p>Many thanks to Sergii Shymko (@<a href="https://twitter.com/SergiiShymko">SergiiShymko</a>) and Willen Wigman (@<a href="https://twitter.com/willemwigman">wigman</a>) for their contributions to this article! 🙏🏽</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb37e8946192" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using CMS blocks effectively in Vue Storefront]]></title>
            <link>https://itnext.io/using-cms-blocks-effectively-in-vue-storefront-8020df888844?source=rss-a2ed5b4c8a17------2</link>
            <guid isPermaLink="false">https://medium.com/p/8020df888844</guid>
            <category><![CDATA[vue-storefront]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Javier]]></dc:creator>
            <pubDate>Mon, 12 Aug 2019 11:31:01 GMT</pubDate>
            <atom:updated>2019-08-16T06:49:13.204Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lpu2JEl-snCXbi4ZNzX0PQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@estherrj?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Esther Jiao</a> on <a href="https://unsplash.com/search/photos/blocks?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>CMS blocks are a popular way to enable users to edit elements in their Magento 2 websites from the backend, it requires (almost) no coding skills and provide a relatively safe way of updating content without risking breaking your e-commerce site.</p><p>Out of the box Vue Storefront provides support for CMS blocks, if you’re using the official <a href="https://github.com/DivanteLtd/magento2-vsbridge-indexer">Magento 2 VS Indexer</a> or <a href="https://github.com/DivanteLtd/mage2vuestorefront">mage2vuestorefront</a> data pump (v1.6+) CMS blocks and pages are synced to the Elastic Search database so we can query this data very efficiently.</p><p>Vue Storefront also includes a component to help us render this content anywhere in our sites, let’s see how that would look if we wanted to make one of the blocks in the homepage editable from a CMS block:</p><h3>1. Use CmsBlock component</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8126fa249615b5ba8cb3b7f421c9851f/href">https://medium.com/media/8126fa249615b5ba8cb3b7f421c9851f/href</a></iframe><p>I chose the PromotedOffers component to make the left-most banner editable, so I replaced it with the &lt;cms-block /&gt; component that takes an identifier(or id) prop that corresponds to the identifier in the Magento 2 admin area.</p><p>All this component does is display the content of the CMS block, keep in mind this will render the HTML as-is so we need to make sure it matches the structure that the Vue Storefront theme expects so it looks good:</p><h3>2. Create CMS Block</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P2ZnVksH_bK6xhcvNhwLGw.png" /><figcaption>CMS block markup from Magento 2 backend</figcaption></figure><blockquote>Make sure the CMS blocks <strong>identifier</strong> matches the one in Vue Storefront</blockquote><p>After saving this and making sure it’s indexed into the Elastic Search database you’ll be able to see the block in the homepage with the new content:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3gIorBDCmUtsvnat-PCYVQ.png" /><figcaption>Photo by <a href="https://unsplash.com/@sonniehiles?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Sonnie Hiles</a> on <a href="https://unsplash.com/search/photos/model?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>This works for a lot of use cases however the biggest drawback is, like mentioned earlier, that the &lt;cms-block /&gt; component will render the block’s content as HTML so Vue can’t really reach it, this means that we won’t be able to use any of the Vue Storefront goodness like:</p><ul><li>Routing</li><li>Lazy loading</li><li>Custom components (like carousels, popups, etc)</li><li>Custom bindings</li><li>Events, etc…</li></ul><p>This also makes CMS blocks harder to maintain because you need to keep a lot of markup in its content, so it can easily be changed by mistake and break the layout of the website.</p><p>Luckily thanks to the modular approach of Vue Storefront we can solve this problem easily.</p><h3>CMS Block Mixin</h3><p>The default CMS Block component does most of what we want out of the box, the only thing we need is a way to parse the content so we’re able to “pluck” out the elements that we need and use them however we want in our Vue Storefront components.</p><p>I figured this would be a common use case so I created a standalone mixin to parse the CMS block content from a string into something that can be more easily manipulated from the frontend.</p><p><a href="https://github.com/jahvi/vsf-cms-block-mixin">jahvi/vsf-cms-block-mixin</a></p><p>I’m using the <a href="https://www.npmjs.com/package/node-html-parser">node-html-parser</a> library to convert the CMS block content into a simplified DOM tree, this means we have access to some of the same low level APIs that we use to query HTML elements:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a396b6cb4aeb1720c8eb014575ac2628/href">https://medium.com/media/a396b6cb4aeb1720c8eb014575ac2628/href</a></iframe><p>With this at hand we can refactor our CMS block implementation, let’s start with the actual markup this time.</p><h3>1. Update CMS block content</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aqf3U2aJyXhCMJBv6ak1Mg.png" /><figcaption>Updated CMS block content</figcaption></figure><p>As you can see now the content has been simplified quite a bit, since we’ll be able to parse this more easily we don’t need to worry about classes, attributes, inline content, etc. In fact the markup almost doesn’t matter now, notice how we’re using an &lt;img&gt; now even though we’ll need it later as a background-image in the frontend.</p><h3>2. Using the new CMS Block Mixin</h3><p>Let’s change our &lt;cms-block /&gt; to use a custom component we’ll create later, just to keep things more organised:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce9b185cd50e3b133f893b85d000d543/href">https://medium.com/media/ce9b185cd50e3b133f893b85d000d543/href</a></iframe><p>Since the implementation of the CMS Block Mixin is pretty much the same as the built in &lt;cms-block /&gt; component nothing much has changed here, however the LeftBanner component is what makes all the magic happen:</p><blockquote>Make sure you’ve ran <em>yarn add vsf-cms-block-mixin before the next step</em></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca582e34e044b55e0dd12847d6498f4f/href">https://medium.com/media/ca582e34e044b55e0dd12847d6498f4f/href</a></iframe><p>As you can see <a href="https://github.com/jahvi/vsf-cms-block-mixin">vsf-cms-block-mixin</a> exposes a parsedContent property that let’s you query elements in a similar way as you’d do in the DOM, so instead of rendering plain HTML we’re actually using Vue Storefront components to display our data, this means:</p><ul><li>We’ve moved the complexity to the frontend, so content is easier to update.</li><li>We’re can make the most out of Vue components, see how we’re using v-lazy to lazy load the background image and &lt;router-link&gt; to render the link without a full page reload.</li><li>The CMS block’s content doesn’t have to follow the same structure as the frontend, as long as it can be queried it can be stored however you want.</li></ul><p>The end result looks the same as before but this time we can see we’re dealing with a real Vue component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*toayw38Y0m4mPOB8vL8tVw.png" /><figcaption>Refactored CMS block in the frontend</figcaption></figure><p>Keep in mind that <a href="https://www.npmjs.com/package/node-html-parser">node-html-parser</a> favours performance over anything else so it only exposers a simplified subset of the APIs available to query HTML elements, but I haven’t found this to be a limitation.</p><h3>Bonus!</h3><p>Depending on where you use CMS blocks you might notice that they don’t load with the page after a full reload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xPhO7oLX64HhJDpsnt-dog.gif" /><figcaption>CMS block loads after page load</figcaption></figure><p>This is because this blocks are not loaded server side so they’re not part of the initial DOM content. We can’t prefetch the CMS data in asyncData in our component or mixin because this only runs for the top-most component and its mixins but we can move this login into the page component where it’s being used, in our case the Home.vue component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd5933c8995ce12001a82a3fb0c774fb/href">https://medium.com/media/dd5933c8995ce12001a82a3fb0c774fb/href</a></iframe><p>Dispatching the cmsBlock/list action with an array of all the CMS blocks that we need in the page will make sure that the block’s data is available before load.</p><blockquote>Keep in mind the asyncData method will be replaced with serverPrefetch in a later version of Vue Storefront</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XrlkXV6Scls_kTI3O35w3Q.gif" /><figcaption>Server rendered CMS block in the frontend</figcaption></figure><p>Cool kids these days are using standalone CMS solutions like <strong>WordPress</strong> or <strong>Contentful</strong> to manage content in Vue Storefront sites but I think this is a very lightweight approach that you can take if you’re already using Magento 2 to manage your e-commerce site.</p><p>Feel free to use and contribute to the module if you find it useful, PRs and suggestions are more than welcome! 👋🏽</p><p><a href="https://github.com/jahvi/vsf-cms-block-mixin">jahvi/vsf-cms-block-mixin</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8020df888844" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/using-cms-blocks-effectively-in-vue-storefront-8020df888844">Using CMS blocks effectively in Vue Storefront</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Magento PWA Studio: What is UPWARD?]]></title>
            <link>https://itnext.io/magento-pwa-studio-what-is-upward-acf450fbee3e?source=rss-a2ed5b4c8a17------2</link>
            <guid isPermaLink="false">https://medium.com/p/acf450fbee3e</guid>
            <category><![CDATA[magento-pwa-studio]]></category>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[magento-2]]></category>
            <dc:creator><![CDATA[Javier]]></dc:creator>
            <pubDate>Mon, 08 Apr 2019 11:01:00 GMT</pubDate>
            <atom:updated>2019-04-09T13:08:44.740Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tIp5uRFxl0k0kyOAoskHIw.jpeg" /><figcaption>Unrelated, please ignore…</figcaption></figure><p>For the past few months Magento has been working on <a href="https://github.com/magento-research/pwa-studio">PWA Studio</a> which is, in summary, a collection of tools to help build modern Progressive Web Applications on top of Magento 2 stores.</p><p>For the most part these tools have been used in production by other projects with great success so it makes sense that PWA Studio is built on top of them, for example:</p><ul><li><strong>Peregrine</strong>: collection of <em>React</em>-based UI components to help reuse common functionality like routing, render pages, products, prices, etc.</li><li><strong>PWA Buildpack: </strong>build and layout optimisation tooling, it expands <em>webpack</em> to help configure PWA Studio components and sets up local development environment.</li><li><strong>Venia</strong>: core storefront built using PWA Studio’s libraries, it uses <em>React</em>, <em>Redux</em>, <em>GraphQL</em>, <em>CSS Modules </em>and many other technologies as part of its stack.</li></ul><p>However there’s something that’s not as well known as the rest. <strong>UPWARD </strong>was built for PWA Studio so it makes sense most people haven’t heard about it but it’s one of its most important pieces, in fact I’d say it’s what glues everything else together.</p><p>But before talking about what it is, it’s important to know why it was made…</p><h3>In the beginning</h3><p>Earlier versions of the Venia storefront used roughly the same technology stack in the frontend but it was still developed as a regular Magento 2 theme, it wasn’t a common approach specially as similar projects like <a href="https://github.com/DivanteLtd/vue-storefront">Vue Storefront</a> or <a href="https://github.com/deity-io/falcon">Deity’s Falcon</a> were going for a more headless approach.</p><p>It made sense to remove this hard dependency on Magento but something was still needed to handle communication between the two. Of course you could deal with Magento’s API directly but:</p><ul><li>What if you had to use multiple APIs, not only Magento’s, how do you organise all these different endpoints?</li><li>What if you need to extend or improve any of the core API’s? If you need to replace some endpoints, is it easy to do so without many side-effects?</li><li>What about third party API’s that are not specific to Magento (social media, shipping calculations, CMS, etc)? Will you need to create custom extensions just to interact with them?</li></ul><p>These are the kind of problems <strong>UPWARD</strong> helps solve by having a single place where requests are made to and always return data the way you expect it to.</p><h3>So what is it then?</h3><p>To put it in simple terms: <strong>UPWARD</strong> is the server that acts as the middle layer between your PWA and your APIs, it has multiple benefits but for me the main one is that it helps unify all APIs in a single place so you don’t have to keep track of multiple endpoints and how to access them.</p><p>Maybe James Zetlen, the mind behind <strong>UPWARD</strong>, can help explain it better:</p><h3>James Zetlen on Twitter</h3><p>@SergiiShymko UPWARD replaces the custom-built server. Instead of writing routes in Node or Rails or Laravel, you put a file in your app which describes a decision tree covering every HTTP call your app can make. Now you can upload that app with any UPWARD server and it Just Works.</p><p>What makes <strong>UPWARD</strong> so unique is that it’s not a server itself, it’s actually a <em>spec </em>that describes how a server should respond when data is requested in different ways. In the same way that <em>GraphQL</em> is a spec and libraries like <em>Apollo </em>and <em>Relay</em> are implementations of this spec, <strong>UPWARD</strong> has officially been implemented in <a href="https://github.com/magento-research/pwa-studio/tree/develop/packages/upward-js">NodeJS</a> and <a href="https://github.com/magento-research/upward-php">PHP</a> but there’s no reason why it can’t be implemented in other technologies.</p><p>The way that <strong>UPWARD</strong> defines how the server behaves is with a YAML configuration file using a special syntax. This file is similar to how the <em>.htaccess</em> file is to Apache servers, they don’t work exactly the same but I found the comparison helps wrap your head around the concept.</p><p>Even though <strong>UPWARD</strong> was made for PWA Studio it is platform agnostic so it can be used for anything that requires interaction with a server, it doesn’t even have to be a PWA!</p><h3>So how does it look like?</h3><p>As with many things it’s usually easier to understand with examples, I’ll showcase some use cases without using any kind of framework because it makes it simpler to explain and doesn’t require any kind of special tooling but you can adapt them to your JS flavour of choice very easily.</p><h3>1. Hello World</h3><p>Let’s start by creating a new node server and installing the required dependencies, I’ll be using yarn for these examples but feel free to use npm if you prefer:</p><pre>yarn add @magento/upward-js express</pre><p><strong>UPWARD-JS</strong> is built on top of <em>express</em> so we need to install it as a peer dependency.</p><p>Now let’s add a single command to our “scripts” block in the package.json file:</p><pre><em>&quot;start&quot;</em>: &quot;node server.js&quot;</pre><p>This will start our server using a <em>server.js</em> file that we’ll create now:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49d410d8356a42d1ac982ff3257ac461/href">https://medium.com/media/49d410d8356a42d1ac982ff3257ac461/href</a></iframe><p>This is one of the simplest ways to start an <strong>UPWARD-JS</strong> server, we only need to call the createUpwardServer function with a few required parameters. Most of them are self-explanatory, all we’re doing here is creating and binding a new server using port 8000, enabling logging for debugging and passing the path to our YAML configuration file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecae2c7cc7741b096413e7cd1b5cb89b/href">https://medium.com/media/ecae2c7cc7741b096413e7cd1b5cb89b/href</a></iframe><p>As you can see the configuration file is fairly easy to read (at least for now…), <strong>UPWARD</strong> requires that we specify at least 3 properties: the server <em>status</em><strong> </strong>code, <em>headers</em> and <em>body</em>. In this case we’re configuring the server to respond to all requests with a 200 response code and the text “Hello World” as HTML in the body.</p><p>Notice the “inline” property lets us define values as strings directly in the configuration file, this is known as a <em>resolver</em> in the <strong>UPWARD </strong>spec and there are more of them we’ll get to know later.</p><p>Now if we run yarn run start and visit <a href="http://localhost:8000/">http://localhost:8000</a> we’ll be able to see the results of our hard work:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLs_XCYigNf_HAzt6CuUjw.png" /><figcaption>Who needs express uh?</figcaption></figure><p>As it is now all URLs will return the same “Hello World” string, efficient but not very useful. Let’s see how we can make something that can actually help us in the real world.</p><h3>2. Proxying requests</h3><p>One of the most common use cases in modern web apps is to interact with multiple APIs, instead of having to track multiple endpoints we can setup our <strong>UPWARD</strong> server to proxy requests to different services so we only need to send requests to it (goodbye CORS issues!).</p><p>For this we need to start using <em>resolvers </em>in our YAML configuration, <em>resolvers</em> define the way data is obtained and it’s defined by a property in our YAML file. In the previous example we used the “Inline Resolver” which returns a string but there are many others available for more complex scenarios.</p><p>Let’s pretend we want to query two different GraphQL APIs, one for retrieving Pokémon data (gotta catch ’em all!) and another one for countries data. These are two different services but we want to set them up so we can use:</p><ul><li><a href="http://localhost:8000/countries/graphql">http://localhost:8000/pokemon/graphql</a> to query one the Pokémon API.</li><li><a href="http://localhost:8000/countries/graphql">http://localhost:8000/countries/graphql</a> to query the countries API.</li></ul><p>We’ll need to extend our configuration file to look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1703b5fcf600f451f308c10fa02a32c/href">https://medium.com/media/e1703b5fcf600f451f308c10fa02a32c/href</a></iframe><p>Ah things looking more interesting, I added some comments to the file as it’s starting to become more of a flowchart. As you can see the status, headers and body is not hardcoded anymore but instead is retrieved by a response property, this can be named however you want but what that means is that <strong>UPWARD</strong> will execute this response to get the values that it needs. Let’s follow the request flow in order:</p><p><strong>#1 response</strong>: this property is using a “Conditional Resolver” which works the same as the PHP switch statement. In this case we’re checking:</p><ol><li>If the URL matches “/pokemon/graphql” it will use the pokemonGQL resolver,</li><li>If it matches “/countries/graphql” it will use the countriesGQL resolver,</li><li>Otherwise use the helloWorld resolver.</li></ol><p><strong>#2, #3 pokemonGQL/countriesGQL: </strong>these properties are using a “Proxy Resolver”, all they do is set the URL for which requests will be proxied to, in our case we hardcoded the URLs for our third-party services using the “Inline Resolvers” we used before.</p><p><strong>#4 helloWorld: </strong>if the URL doesn’t match any of the previous we’ll return the same “Hello World” string as before, I just moved the configuration to its own resolver now.</p><p>Since nothing else needs to be resolved <strong>UPWARD</strong> can finally return the response, if everything went right we should have access to our brand new endpoints:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*IgXar79I9etNDfUzNibRZw.gif" /></figure><h3>3. Rendering HTML</h3><p>Displaying a “Hello World” string is super performant but not very useful, so let’s change it up a bit to show more complex HTML markup and explore other types of resolvers.</p><p>By default <strong>UPWARD</strong> supports using the Mustache templating system, it’s very lightweight and basic in terms of features but that’s often a good thing as it prevents us from having too much logic mixed in with our templates. If you want to know more about it feel free to read the <a href="https://github.com/janl/mustache.js">official repo</a>.</p><p>So let’s use Mustache to display some Pokémon data instead of the “Hello World” string, which will also be a good chance to use a “Service Resolver”:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6bc122be5d46136032f44648bcbcce22/href">https://medium.com/media/6bc122be5d46136032f44648bcbcce22/href</a></iframe><p>The first part of the configuration file is the same, but things start to look different in the response property:</p><p><strong>#2, #3 pokemonGQL/countriesGQL:</strong> Instead of hardcoding the GraphQL endpoints I changed it to use environment variables, they can be set by passing an env parameter to the createUpwardServer function or by using libraries like <a href="https://www.npmjs.com/package/dotenv">dotenv</a>. In any case, this can help make our configuration more customisable as you can have different values per environment.</p><p><strong>#4 pokemon:</strong> We’ll be using the “pokemon” property as the default response now. For this we’ll use a “Template Resolver” to render the body with a Mustache template, this can be set in its own file and we can pass the path to it to keep things more organised. Notice the provide property here as well, this defines the data that will be available in our template which in turn can be a resolver as well, let’s keep going down the rabbit hole.</p><p><strong>#5 pokemonData:</strong> This will make more sense once we go one step further, for now understand that this is calling another “pokemonResult” property.</p><p><strong>#6 pokemonResult:</strong> “Service Resolvers” allows us to obtain data from a GraphQL service so we’ll use just that to get the Pokémon information. It takes the url to the endpoint and query as a parameter which we’re hardcoding inline for now to return Pikachu’s stats. If we go back the our previous “pokemonData” value pokemonResult.data.pokemon we can see that this maps to the result we get from the GraphQL query:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BEyOhCUTBoyIdysScEwkAw.png" /><figcaption>GraphQL response data</figcaption></figure><p>What this means is that all the data from the pokemon node will be available in our Mustache template now:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb68440bfbb7aab39cd660eb39a797e7/href">https://medium.com/media/fb68440bfbb7aab39cd660eb39a797e7/href</a></iframe><p>This is very useful for Server Side Rendering and the content will be sent from the server once all the resolvers have been executed. Now if we go to any URL in our <strong>UPWARD</strong> server (except the proxied GraphQL ones) we should see Pikachu’s amazing stats:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rwp5WEEqu_EZKhTElmUafA.png" /><figcaption>Mustache template rendering</figcaption></figure><h3>4. Using variables</h3><p>It would be nice to be able to fetch a specific Pokémon stats by its name using the URL so let’s do just that. We’ll clean up the configuration file a bit more to make it easier to read and add a few more resolvers to it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/183e2dc2a41154fa429e49a1b082d8da/href">https://medium.com/media/183e2dc2a41154fa429e49a1b082d8da/href</a></iframe><p>The configuration is mostly the same with a few tweaks and additions:</p><p><strong>#1 response:</strong> there’s an additional conditional check here to see if we’re requesting the favicon or a CSS file, for both cases we’ll use a “Static Resolver” (#8) which basically returns the files as-is in the “static” folder (no magic here).</p><p><strong>#6 pokemonResult: </strong>we moved the GraphQL code to it’s own file and wrapped it with a query so we can pass variables to it, then specify them with a variables node in the property that points to another “Conditional Resolver”.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2253a2326876f5eb0a5e61a661f6671/href">https://medium.com/media/a2253a2326876f5eb0a5e61a661f6671/href</a></iframe><p><strong>#7 pokemonName:</strong> just as in #1 we are checking if the URL matches a specific pattern (anything beginning with forward slash), if so we return it using the special keyword $match.$1, this is the value that will be used for the GraphQL query above.</p><p>Now with some sprinkles of CSS we should be able to see the stats for all Pokémons available in the API by passing the name in the URL:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*9TUFTGVCbgyvnOT6_U_Cgw.gif" /><figcaption>Credits to Bidji for the <a href="https://codepen.io/Bidji/pen/MYdPwo">Pokedex styles</a></figcaption></figure><p>As you can see <strong>UPWARD</strong> allows us to implement some interesting functionality without writing almost any javascript, however if you are more comfortable with NodeJS or if you already have an <em>express</em> server you can use <strong>UPWARD</strong> as a middleware as well so it can be used as an add-on to your current server and introduce in a more incremental approach instead of replacing <em>express</em> in one go.</p><p>So your server.js could look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0fef4f44423d1a8195052af8980757b7/href">https://medium.com/media/0fef4f44423d1a8195052af8980757b7/href</a></iframe><p>Then requests going to the / route will be served with <em>express</em> and the rest will be outsourced to <strong>UPWARD</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*ixKMgMFF3NS6bMOts25eTg.gif" /></figure><h3>In summary</h3><p><strong>UPWARD</strong> can give us a lot of control and customisation over our server without having to interact directly with <em>express</em> or other technologies like this. Even in its early days I’m surprised at how much it allows us to do out of the box so I’m hopeful it will keep getting better and better.</p><p>If you want to try it for yourself have a look at the spec’s <a href="https://github.com/magento-research/pwa-studio/tree/develop/packages/upward-spec">official Github repo</a>, I noticed it’s not very up to date and in most cases the examples don’t work which makes sense as the project keeps changing quite rapidly so I recommend diving into the <a href="https://github.com/magento-research/pwa-studio/tree/develop/packages/upward-js">UPWARD JS code</a> or the <a href="https://github.com/magento-research/pwa-studio/tree/develop/packages/venia-concept">Venia implementation</a> to get the latest and greatest features.</p><p>All the examples in the article are available in Github so feel free to play around with it and submit any changes or improvements. 👋🏽</p><p><a href="https://github.com/jahvi/upward-examples">jahvi/upward-examples</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acf450fbee3e" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/magento-pwa-studio-what-is-upward-acf450fbee3e">Magento PWA Studio: What is UPWARD?</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating an animated wishlist component for Vue Storefront]]></title>
            <link>https://medium.com/the-vue-storefront-journal/creating-an-animated-wishlist-component-for-vue-storefront-9de8d0ada2ea?source=rss-a2ed5b4c8a17------2</link>
            <guid isPermaLink="false">https://medium.com/p/9de8d0ada2ea</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[css-animation]]></category>
            <category><![CDATA[vue-storefront]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Javier]]></dc:creator>
            <pubDate>Mon, 04 Mar 2019 13:01:00 GMT</pubDate>
            <atom:updated>2019-03-05T08:10:02.388Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*am0PuqNgGuVXvb3niHJuxQ.jpeg" /></figure><p>I was browsing the <a href="https://www.asos.com/">ASOS</a> website the other day and noticed they have a really nice animation when you click the icons to save some items for later:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*RW2WxunLLCj3F3o3XzO2JQ.gif" /><figcaption>ASOS “saved items” icon animation</figcaption></figure><p>So I was wondering if it would be easy to replicate this in<a href="https://vuestorefront.io/?utm_source=medium&amp;utm_medium=social&amp;utm_campaign=medium_ext&amp;utm_content=medium_ext"> Vue Storefront</a>, after all it’s mostly just CSS animations with some JS sprinkled on top, and it turns out it was very simple.</p><h3>1. Create the component structure</h3><p>There’s a wishlist component already in the Vue Storefront core, we could work directly on top of that but it’s probably a better idea to create a new one based on this because we’ll be changing quite a few things.</p><p>Let’s start by copying the contents of src/themes/default/components/core/blocks/Wishlist/AddToWishlist.vue into a new file, let’s call it AddToWishlistButton.vue and place it in the src/themes/default/components/theme/blocks/Wishlist/ folder.</p><p>We can strip a lot of the original component’s code and replace it with our custom CSS styles, initially it will look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c97d31dc0946e3acf987634192593843/href">https://medium.com/media/c97d31dc0946e3acf987634192593843/href</a></iframe><p>Thanks to the magic of the internet I was able to use most of the original button’s code (like the SVG icon and animation keyframes) but also changed a few things here and there to make it look better, the main ideas so far are:</p><ul><li>Using :class=&quot;{ active: isOnWishlist }&quot; to toggle an active class on the element that will trigger the animation when the item is added to the wishlist.</li><li>The CSS animation is scaling the icon up and down and the custom cubic-bezier makes it look more like a “heartbeat”. I’m also adding a transition to the SVG’s fill property so the icon slowly fills up instead of changing all of a sudden like on the original.</li></ul><h3>2. Import in product grid</h3><p>Now to include this in our product grid we need to find the src/themes/default/components/core/ProductTile.vue component and import our custom wishlist button there:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21375957f7e10f87b15f3688c1a0bdc4/href">https://medium.com/media/21375957f7e10f87b15f3688c1a0bdc4/href</a></iframe><p>I removed the irrelevant parts of the code but all we’re doing here is importing our custom component and including it in the markup, as of Vue Storefront 1.7 the wishlist component can be lazy loaded so we can use a dynamic import and a named webpack bundle to split the code into its own file so performance is not badly affected.</p><p>I also added some custom CSS to position the wishlist button in the lower right portion of the product image, so far it looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*Tp2EFNVi6_Gnf9fJ_KsV4w.gif" /><figcaption>Initial implementation of wishlist button</figcaption></figure><p>Looks pretty good as they are but they’re still missing the nicest touch, the floating hearts 💕</p><h3>3. Add floating hearts animation</h3><p>Looking at the original button the hearts are rendered using two &lt;span&gt; tags and another custom animation that changes their opacity and translate properties so they’re moved from the centre of the icon to a random point away from it which is set using CSS variables (or custom properties).</p><p>We’ll ignore the randomly generated points for now and get the animation working with fixed values. All we need for now are a couple &lt;span&gt; tags and some custom CSS:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dcc4081e12c7baa7c883e16327b61598/href">https://medium.com/media/dcc4081e12c7baa7c883e16327b61598/href</a></iframe><p>What we’re doing now is styling our new &lt;span&gt; tags so they look like small hearts (using an SVG background) and position them in the middle of the big heart with position: absolute and opacity: 0. Then, when the active class is triggered, we use our custom animation to change the opacity and translate values based on the hard coded CSS values we set in the markup.</p><p>I tweaked the original animation because I though the original started too soon, I felt it would look nicer if it would look as if the smaller hearts were getting pushed out to the sides from the weight of the bigger heart coming down.</p><blockquote>Will most people notice? Probably not. Was it a waste of time? Most certainly. But I thought it was a nice touch 👌🏽</blockquote><p>Now our wishlist button looks a lot better:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*9PokHooN069yIvfFqgzecA.gif" /><figcaption>Floating hearts animation</figcaption></figure><h3>4. Randomise the floating hearts animation</h3><p>Almost there! Now we need to find a way of randomising the small heart’s final position so they always move differently.</p><p>We’re already using CSS variables so it’s just a matter of changing the hardcoded values to randomly generated ones. Now, I’m not sure what the original logic for these are but I think that picking a random value from 5 to 20 pixels for both X and Y coordinates should do the trick.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca466b9962e9c038229db835f077c0d0/href">https://medium.com/media/ca466b9962e9c038229db835f077c0d0/href</a></iframe><p>We changed the hard coded coordinates with a custom method that returns a random number from 5 to 20, and also give it a 50% chance of changing the number to a negative value so the small hearts don’t always float away in the same direction.</p><p>We can now sit back and enjoy our new creation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*QmPXHfDfXG1KDazrgN7EkQ.gif" /><figcaption>Randomised floating hearts animation</figcaption></figure><p>The best part is that since we’re leveraging strategies like code splitting and animating cheap CSS properties like opacity and transform, it makes our custom component not only look good but also perform quite well.</p><p>I created a repo with the code in <a href="https://github.com/jahvi/vue-storefront-wishlist-button">GitHub</a>, feel free to have a look and submit PRs or report any issues. 👋🏽</p><p><a href="https://github.com/jahvi/vue-storefront-wishlist-button">https://github.com/jahvi/vue-storefront-wishlist-button</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9de8d0ada2ea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-vue-storefront-journal/creating-an-animated-wishlist-component-for-vue-storefront-9de8d0ada2ea">Creating an animated wishlist component for Vue Storefront</a> was originally published in <a href="https://medium.com/the-vue-storefront-journal">The Vue Storefront Journal</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to stop content jumping when images load?]]></title>
            <link>https://itnext.io/how-to-stop-content-jumping-when-images-load-7c915e47f576?source=rss-a2ed5b4c8a17------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c915e47f576</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Javier]]></dc:creator>
            <pubDate>Mon, 28 Jan 2019 12:51:00 GMT</pubDate>
            <atom:updated>2019-01-29T10:52:13.470Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aKPNdhoHgZ2nUMt0cJQfKQ.jpeg" /></figure><p>Images are widely used in most websites, web apps and PWAs, have a look at any of your recent projects and it’s likely that images are responsible for a good portion of its bundle size.</p><p>Because of this you might have run into this scenario: you have a mix of images and text based content in your page but, as images load, the whole layout shifts, jumps and changes providing a very poor user experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*0EHbaworlZeRN1LOeK9PpQ.gif" /><figcaption>Content jumps around as images load</figcaption></figure><p>This is particularly worse on mobile devices due to the limited screen sizes and connection speeds. Also it doesn’t help that modern best practices recommend lazy loading images below the fold because it means the jumping and shifting will continue as users scroll down the page.</p><h3>Just set a width and height on the images?</h3><p>Oh if only life was that easy, the truth is that setting the width and height of images does let the browser “reserve” the image space before it loads as it knows how big it will be ahead of time, however there’s a huge caveat, <em>it doesn’t work at all if the image is responsive.</em></p><p>In most cases you’ll have CSS like this to make sure images will scale down nicely:</p><pre>img {</pre><pre>    max-width: 100%;</pre><pre>    height: auto;</pre><pre>}</pre><p>That height: auto will “nullify” the fixed height attribute, with good reason, and now the browser have no way of knowing how big the image needs to be without loading it.</p><h3>The aspect ratio padding trick</h3><p>Images scale up and down based on its aspect ratio, so knowing this we can use of the oldest CSS tricks to solve this problem.</p><p>The <a href="https://css-tricks.com/aspect-ratio-boxes/">aspect ratio padding trick</a> is often use to help with responsive videos and SVGs, it relies on the fact that padding in percentages is based on the element width, which can help us with the content jumping problem.</p><p>All we need is to wrap the images in a zero height container and give a padding-top with the same aspect ratio of the image, eg:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9fc2e33b05848c1d73c8a1bdef83d4c/href">https://medium.com/media/a9fc2e33b05848c1d73c8a1bdef83d4c/href</a></iframe><p>You don’t even need to use calc here it just helps visualise it better, all you need is to get the image aspect ratio based on the following formula:</p><blockquote>(height / width * 100</blockquote><p>Now as you can see on the following pen we’ve avoided the dreaded content jump, even when images take a while to load:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fjaviervd%2Fembed%2Fpreview%2FyZOEXM%3Fheight%3D600%26slug-hash%3DyZOEXM%26default-tabs%3Dhtml%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2Fjaviervd%2Fpen%2FyZOEXM%3Feditors%3D1100&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fm.cdpn.io%2Fscreenshot-coming-soon-small.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a6a303e3b8a58c2d9477c778c8e399d/href">https://medium.com/media/8a6a303e3b8a58c2d9477c778c8e399d/href</a></iframe><h3>BONUS: Sprinkle some JS on top</h3><p>Since a lot of us are using some sort of component-based javascript framework we can make a new Img component to help reuse our new images, we can also add some lazy loading features and fancy loading indicators just for fun.</p><p>I’ll be using ReactJS in this example but it should also be doable in your framework of choice, the basic concepts will be the same:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa6576867d590b9a061ace7c0f46a873/href">https://medium.com/media/fa6576867d590b9a061ace7c0f46a873/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e30545cad3c806ae18b699ece2c4b7f/href">https://medium.com/media/1e30545cad3c806ae18b699ece2c4b7f/href</a></iframe><p>It looks more complicated but in essence it’s the same idea as the static html/css counterpart. The .wrapper element will act as the padded container and the .img element will be absolutely positioned inside.</p><p>We could have used inline styles to set the padding-top on the container based on the image size but by using CSS variables we’ve added an extra buzzword to our component which is nice to have this day and age.</p><p>I’m also using the <a href="https://github.com/thebuilder/react-intersection-observer">react-intersection-observer</a> library that provides a render prop with an inView parameter that lets me know when the image is inside the viewport and added some CSS animations to show a loading indicator when images are being loaded.</p><p>In the end our Img component can be used like any other img element:</p><pre>&lt;Img</pre><pre>    width={360}</pre><pre>    height={360}</pre><pre>    src=&quot;https://loremflickr.com/360/360/cat&quot;</pre><pre>    alt=&quot;Cute cat&quot;</pre><pre>/&gt;</pre><p>With the benefit that now we have a reusable image component that includes:</p><ul><li>Lazy loading.</li><li>Avoids content jumps.</li><li>Loading indicator.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*wXB9lSMvH6VEQ_FngWaasg.gif" /><figcaption><a href="https://codesandbox.io/s/1642lz7n7">https://codesandbox.io/s/1642lz7n7</a></figcaption></figure><p>Feel free to play around with the demo and improve it as you see fit, feedback is always welcome! 👋🏽</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c915e47f576" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/how-to-stop-content-jumping-when-images-load-7c915e47f576">How to stop content jumping when images load?</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create an Instagram Feed module for Vue Storefront]]></title>
            <link>https://itnext.io/how-to-create-an-instagram-feed-module-for-vue-storefront-eaa03019b288?source=rss-a2ed5b4c8a17------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaa03019b288</guid>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[magento-2]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[ecommerce-web-development]]></category>
            <dc:creator><![CDATA[Javier]]></dc:creator>
            <pubDate>Wed, 02 Jan 2019 13:01:01 GMT</pubDate>
            <atom:updated>2019-01-08T12:59:56.787Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6H10HxJeTgzxlEQPSKGgRQ.jpeg" /><figcaption>Random gallery photo</figcaption></figure><p>I’ve been working with <a href="https://www.vuestorefront.io/">Vue Storefront</a> for the past few months and it’s been a great experience. It’s one of the few open-source solutions available to implement PWAs using Magento 2 (and many other e-commerce platforms) in the backend so it brings modern solutions out of the box to a lot of common requirements for web based applications (offline support, lazy loading, small bundle size, server side rendering, etc).</p><p>To get a basic understanding of how Vue Storefront works I thought it would be a good idea to document how to implement an Instragram feed in your store. It’s a relatively simple tasks but it involves many core concepts of Vue Storefront so it can be a useful case of “learn by doing”.</p><h3>Before we start</h3><p>It’s important to understand the Vue Storefront is a collection of multiple “pieces” working together, not a single big entity. The most significant ones would be:</p><ul><li><a href="https://github.com/DivanteLtd/vue-storefront">vue-storefront</a>: handles the frontend of the store, it’s powered by (you guessed it) VueJS and many other packages that determine how the data should be displayed.</li><li><a href="https://github.com/DivanteLtd/vue-storefront-api">vue-storefront-api</a>: since Vue Storefront is 100% platform agnostic this service is needed to act as a middle layer between the frontend and the backend. In most cases we’ll use it to connect to Magento but it can interact with any number of providers, eg: WordPress, MailChimp, or in this case Instagram.</li></ul><p>If you’re interested in knowing more about Vue Storefront architecture I recommend giving the <a href="https://www.youtube.com/watch?v=sRSmEP4jva0&amp;feature=youtu.be">official technical screencast</a> a watch as it does a better job at explaining all the tools behind it that I ever could in this article.</p><h3>Setting up the API endpoint</h3><p>To get a user’s Instagram feed we need to use an access token to query Facebook’s Graph API. It’s not ideal to expose this kind of information in the front-end as it can lead to security vulnerabilities so we should do this server-side.</p><p>Luckily we can easily extend <strong>vue-storefront-api</strong> with custom endpoints that return the data we need. 🎉</p><p>We’ll start by creating the following index.js file in src/api/extensions/instagram-api/:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e9b2ce20165f816ffb5485e7b0e6ca7/href">https://medium.com/media/7e9b2ce20165f816ffb5485e7b0e6ca7/href</a></iframe><p>Basically what this does is extend Vue Storefront’s express Router with a new /feed endpoint that will make a request to Facebook’s Graph API with our page ID and access token. If there’s any error it will return a 500 status code with the error response, if not it will return the user’s Instagram feed as a JSON array.</p><blockquote>It also accepts an optional “limit” parameter to specify the maximum number of items to return.</blockquote><p>As you can see we didn’t hardcode the page ID or the access token, as they will be project-specific these should be stored in the config/local.json file.</p><p>Open the local.json file and add an instagram key to the extensions list with the following information:</p><pre>&quot;instagram&quot;: {<br>  &quot;pageId&quot;: &quot;FB PAGE ID&quot;,<br>  &quot;accessToken&quot;: &quot;FB PAGE ACCESS TOKEN&quot;<br>}</pre><p>To get your page ID follow these instructions: <a href="https://www.facebook.com/help/community/question/?id=378910098941520">facebook.com/help/community/question/?id=378910098941520</a></p><p>To get a “never expire” access token follow this SO answer: <a href="https://stackoverflow.com/a/35481577/455319">stackoverflow.com/a/35481577/455319</a></p><p>Now to enable our extension add “instagram-api” to the list of registeredExtensions in your local.json config file as well.</p><p>If everything went well you should see a list of the latest Instagram posts when you visit our custom <strong>vue-storefront-api</strong> endpoint /api/ext/instagram-api/feed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bg7-rKbo4HmKcVqOLoYmrQ.png" /><figcaption>Custom Instagram API endpoint</figcaption></figure><h3>Setting up frontend component</h3><p>Now that we have a way to securely retrieve our Instagram feed we can start thinking about how to display it. Since version 1.6 Vue Storefront encourages the use of modules to extend its functionality so this can be a good use case to use one.</p><p>Let’s create the following files in the src/modules/instagram-feed folder:</p><p><strong>index.ts</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6720d5b83dfa1d41eda41e5d9e37ef0d/href">https://medium.com/media/6720d5b83dfa1d41eda41e5d9e37ef0d/href</a></iframe><p>This is the entry point for our module, it’s mostly boilerplate code that sets up all the data required by our module. In our case it just registers a new module with the instagram-feed name and registers the <strong>Vuex store</strong>.</p><p><strong>store/index.ts</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4ccc3a5a42edfc91d9ed3ee1abc845c/href">https://medium.com/media/e4ccc3a5a42edfc91d9ed3ee1abc845c/href</a></iframe><p><strong>store/mutation-types.ts</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0fd94456683cca86796c93aa4c69fb69/href">https://medium.com/media/0fd94456683cca86796c93aa4c69fb69/href</a></iframe><p>This creates the actions, getters and mutations for Vue Storefront’s <strong>Vuex store</strong>. The most important part is the get action that makes a request to the API we created earlier to fetch the latest Instagram posts, since this endpoint can be variable it’s a good idea to also store it in the config/local.json file, so make sure to create a new parameter as well:</p><pre>&quot;instagram&quot;: {<br>  &quot;endpoint&quot;: &quot;<a href="http://localhost:8080/api/ext/vue-storefront-instagram-api/feed">http://your-vue-storefront-api-url.com/api/ext/instagram-api/feed</a>&quot;<br>}</pre><p><strong>components/InstagramFeed.js</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4783f929f63ada07e68cf8a4dc0ebb08/href">https://medium.com/media/4783f929f63ada07e68cf8a4dc0ebb08/href</a></iframe><p>Finally our custom component which can be used as a mixin, gets the latests Instagram posts from the <strong>Vuex</strong> <strong>store</strong> on mount and exposes a feed property that can be used in the template. It also allows us to change the feed limit with a custom limit prop.</p><p>Now to register our custom module we include it in the src/modules/index.ts file:</p><pre>// Import module at the top<br>import { InstagramFeed } from &#39;../modules/instagram-feed&#39;</pre><pre>// Add to &quot;registerModules&quot; array<br>export const registerModules: VueStorefrontModule[] = [<br>  ...<br>  InstagramFeed<br>]</pre><h3>Displaying feed in the frontend</h3><p>To finish it off all we need to do is create the markup to actually show the feed in our website.</p><p>To save some time let’s reuse the code that renders the “Get inspired” section that comes in the default theme. Create a InstagramFeed.vue file in src/themes/default/components/theme/blocks/InstagramFeed/InstagramFeed.vue:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48d8fbac2cb6098e891cfed4b3c4fd7c/href">https://medium.com/media/48d8fbac2cb6098e891cfed4b3c4fd7c/href</a></iframe><p>This looks pretty much the same as the default TileLinks.vue file, all we do here is use our InstagramFeed mixin and loop over the feed computed property to render the available media.</p><p>Let’s display our custom component on the homepage of our store, open the Home.vue in src/themes/default/pages/Home.vue and include the markup for the element we just created:</p><pre>&lt;template&gt;<br>  ...<br>  &lt;section class=&quot;container pb60 px15&quot;&gt;<br>    &lt;div class=&quot;row center-xs&quot;&gt;<br>     &lt;header class=&quot;col-md-12 pt40&quot;&gt;<br>        &lt;h2 class=&quot;align-center cl-accent&quot;&gt;<br>          {{ $t(&#39;Instagram&#39;) }}<br>        &lt;/h2&gt;<br>      &lt;/header&gt;<br>    &lt;/div&gt;<br>    &lt;instagram-feed limit=&quot;8&quot; /&gt;<br>  &lt;/section&gt;<br>  ...<br>&lt;/template&gt;</pre><pre>&lt;script&gt;<br>...<br>import InstagramFeed from &#39;theme/components/theme/blocks/InstagramFeed/InstagramFeed&#39;</pre><pre>export default {<br>  components: {<br>    ...<br>    InstagramFeed<br>  }<br>}<br>&lt;/script&gt;</pre><p>If everything is right we’ll be able to see our Instagram feed on the homepage:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OkpKB94kE9R0Bl3yuqEFgw.png" /><figcaption>Instagram feed on the homepage</figcaption></figure><p>The cool thing about it is that since we’re reusing the TileLink component markup we get the lazy loading and CSS transitions for free.</p><h3>Wrapping up</h3><p>We managed to use a good portion of the technologies that are part of Vue Storefront, however there are still a few things that can be improved, eg:</p><ul><li>TypeScript implementation</li><li>Caching feed</li><li>Storing media in Elastic Search</li><li>And much more…</li></ul><p>But as a quick introduction this module should showcase some of the features that make Vue Storefront a great tool to build e-commerce stores with. 👋🏽</p><p>The code for the module is available in GitHub, feel free to submit any issues and pull requests:</p><ul><li><a href="https://github.com/jahvi/vue-storefront-instagram-feed">jahvi/vue-storefront-instagram-feed</a></li><li><a href="https://github.com/jahvi/vue-storefront-instagram-api">jahvi/vue-storefront-instagram-api</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaa03019b288" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/how-to-create-an-instagram-feed-module-for-vue-storefront-eaa03019b288">How to create an Instagram Feed module for Vue Storefront</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>