<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>webdev on Wouter Bulten</title>
    <link>https://www.wouterbulten.nl/tags/webdev/</link>
    <description>Recent content in webdev on Wouter Bulten</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <copyright>Copyright Wouter Bulten (except otherwise noted) &amp;copy; 2023 • All rights reserved.
</copyright>
    <lastBuildDate>Tue, 30 May 2017 00:00:00 +0000</lastBuildDate><atom:link href="https://www.wouterbulten.nl/tags/webdev/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Website upgrade &amp; Jekyll blog optimizations</title>
      <link>https://www.wouterbulten.nl/posts/website-upgrade-and-jekyll-optimizations/</link>
      <pubDate>Tue, 30 May 2017 00:00:00 +0000</pubDate>
      
      <guid>https://www.wouterbulten.nl/posts/website-upgrade-and-jekyll-optimizations/</guid>
      <description>It has been over two years since the last full update of my website itself and it was time for an upgrade!</description>
      <content:encoded><![CDATA[<p>It has been over two years since the last full update of my website itself and it was time for an upgrade! I started from scratch and rebuild the whole underlying Jekyll structure and all of the CSS. The main goal was to create a new fresh design while keeping the site light and clean. With a score of <em>A(98%)/A(97%)</em> on <a href="https://gtmetrix.com">GTmetrix</a> and <em>99/99</em> using PageSpeed Insights the latter has been achieved; the design is of course a matter of personal taste. An overview of some of the key statistics:</p>
<table>
<thead>
<tr>
<th>Page</th>
<th>Home</th>
<th>About page</th>
<th>Blog Tech index</th>
</tr>
</thead>
<tbody>
<tr>
<td>PageSpeed (Mobile, Desktop)</td>
<td>99, 99</td>
<td>99, 99</td>
<td>99, 95</td>
</tr>
<tr>
<td>YSlow</td>
<td>97%</td>
<td>98%</td>
<td>98%</td>
</tr>
<tr>
<td>KB</td>
<td>178KB</td>
<td>158KB</td>
<td>35.3KB</td>
</tr>
<tr>
<td>Loading time</td>
<td>852ms</td>
<td>869ms</td>
<td>919ms</td>
</tr>
<tr>
<td># requests</td>
<td>8</td>
<td>5</td>
<td>4</td>
</tr>
</tbody>
</table>
<p>Although some things can still be improved, I am very happy with these results. These high speed scores show that you can really achieve good performing sites using lightweight systems such as Jekyll. In the remainder of this post I give a small overview of some of the changes and the techniques that are used to build this site.</p>
<h2 id="no-more-jquery--less-js">No more jQuery / less JS</h2>
<p>The old website used jQuery on every page for some basic functionality. Now only the interactive posts load jQuery as some of the scripts and libraries depend on it. These scripts are of course loaded asynchronously. All other/regular pages only use <a href="http://vanilla-js.com/">vanillajs</a> for some basic functionality. Removing jQuery has greatly improved the overall page load/rendering time.</p>
<h2 id="new-design-better-css-loading">New design, better CSS loading</h2>
<p>I discarded all the old CSS and started from scratch using the <a href="http://getbootstrap.com/">Bootstrap 4</a> reboot and grid builder mixins. All styles are written in Sass and compiled using <a href="https://github.com/sass/node-sass">node-ass</a> and <a href="http://postcss.org/">PostCSS</a>.
<a href="https://github.com/filamentgroup/loadCSS">loadCSS</a> is used to asynchronously load the css and <a href="https://github.com/addyosmani/critical">critical</a> for generating the above-the-fold inline css.</p>
<p>In three steps all css is generated from my base files:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl"><span class="c1"># Convert sass to css</span>
</span></span><span class="line"><span class="cl">node-sass &lt;input&gt; --output-style compressed --output &lt;css output&gt;
</span></span><span class="line"><span class="cl"><span class="c1"># Add necessary vendor prefixes</span>
</span></span><span class="line"><span class="cl">postcss --no-map.inline --use autoprefixer postcss-flexbugs-fixes -o &lt;input&gt; &lt;css output&gt;
</span></span><span class="line"><span class="cl"><span class="c1"># Compute the inline css (for above the fold)</span>
</span></span><span class="line"><span class="cl">node inline-css.js
</span></span></code></pre></div><p>The <code>inline-css.js</code> file is a small node script that uses <a href="https://github.com/addyosmani/critical">critical</a> for generating the above-the-fold CSS. The generated css is included in the head by Jekyll automatically. In fact, different versions of the above-the-fold css are generated depending on the page type.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-javascript" data-lang="javascript"><span class="line"><span class="cl"><span class="kd">var</span> <span class="nx">critical</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;critical&#39;</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">// Example of generating above the fold css
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="nx">critical</span><span class="p">.</span><span class="nx">generate</span><span class="p">({</span>
</span></span><span class="line"><span class="cl">    <span class="nx">base</span><span class="o">:</span> <span class="s1">&#39;../&#39;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nx">src</span><span class="o">:</span> <span class="s1">&#39;_site/index.html&#39;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nx">dest</span><span class="o">:</span> <span class="s1">&#39;_includes/critical-css.css&#39;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nx">minify</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nx">width</span><span class="o">:</span> <span class="mi">1300</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nx">height</span><span class="o">:</span> <span class="mi">900</span>
</span></span><span class="line"><span class="cl"><span class="p">});</span>
</span></span></code></pre></div><h2 id="privacy-aware-analytics">Privacy-aware analytics</h2>
<p>While I used Google Analytics to register traffic on my website, I do not mind people blocking this. To still get some sense of traffic a small script registers whenever someone visits a page. This script discards the IP address of the visitor (and other user info) and only logs the page and (if possible) the country of origin.</p>
<h2 id="blog-software">Blog software</h2>
<p>The blog and all of the pages are powered by <a href="https://jekyllrb.com/">Jekyll</a> (now using version 3). I use some small tweaks to further optimize the build, such as minimzing all html output at build time. Posts are annotated using <a href="http://schema.org/">Schema.org</a> to structure the data for search engines.</p>
<h2 id="hosting">Hosting</h2>
<p>The site is (still) hosted using <a href="https://pages.github.com/">GitHub Pages</a> and <a href="https://www.cloudflare.com/">CloudFlare</a> is used to optimize the delivery (and cache as much as possible in one of their edge nodes).</p>
<h2 id="feedback">Feedback?</h2>
<p>So far for the updates! As the site is still new and actively developed, any feedback is welcome. Please add a comment below if you have any tips or found a bug. You can also use the <a href="/contact/">contact form</a>. Thanks :)</p>
]]></content:encoded>
    </item>
    
    <item>
      <title>Blog Optimization: Replacing Font Awesome with SVG</title>
      <link>https://www.wouterbulten.nl/posts/blog-optimization-replacing-font-awesome-with-svg/</link>
      <pubDate>Tue, 01 Mar 2016 00:00:00 +0000</pubDate>
      
      <guid>https://www.wouterbulten.nl/posts/blog-optimization-replacing-font-awesome-with-svg/</guid>
      <description>My blog is hosted using Jekyll which is a static site generator. Static sites are inherently fast, but I took some extra measures to achieve an even faster website. This is part 1 of the series: replacing Font Awesome.</description>
      <content:encoded><![CDATA[<p>This post is the first in a series of (micro) optimizations I did to my Jekyll blog. Each post will focus on a single optimization and shows how you can apply this to your own (Jekyll) blog. Some of these posts will be focussed primarily on blogs using Jekyll and Github Pages, others will be less specific and focus on performance on the web in general.</p>
<p>Today we kick-off with SVG icons!</p>
<h2 id="the-problem">The problem</h2>
<p><a href="https://fortawesome.github.io/Font-Awesome/">Font Awesome</a> is a great free icon font which doesn&rsquo;t require an introduction. The list of included icons is large and the ease of use makes it a great choice for web applications.</p>
<p>However, on a blog like this most users will only visit a few pages at most. Most traffic comes from search engines and visitors are probably looking for an answer to a specific question. So, to cater for these users we need to optimize the performance as if every users stats with an empty cache. This is in contrast to more high-feature web applications that engage users for a longer amount of time.</p>
<p>To improve performance the first strategy is to improve loading of the website. This includes the amount of requests, the total size of the page and the rendering.</p>
<p>After a small search I found out that my theme used Font Awesome for the staggering amount of <em>four</em> icons. In other words, to display 5 icons a user needs to load the Font Awesome css and the font itself. We can do better right?</p>
<h2 id="icon-definition-list">Icon definition list</h2>
<p>A few of the simple icons (such as a downward facing arrow) I replaced with HTML entities (such as ↓). The more complex icons (Github/LinkedIn icons as an example) were a bit harder to replace. My solution was to create a small SVG icon library in the Jekyll theme.</p>
<p>Using a tool such as <a href="https://icomoon.io/app/">IcoMoon</a> you can easily generate SVG symbols for common-used icons. The Github and LinkedIn icons for example give the following definition:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-xml" data-lang="xml"><span class="line"><span class="cl"><span class="nt">&lt;symbol</span> <span class="na">id=</span><span class="s">&#34;icon-linkedin&#34;</span> <span class="na">viewBox=</span><span class="s">&#34;0 0 1024 1024&#34;</span><span class="nt">&gt;</span>
</span></span><span class="line"><span class="cl">  <span class="nt">&lt;title&gt;</span>linkedin<span class="nt">&lt;/title&gt;</span>
</span></span><span class="line"><span class="cl">  <span class="nt">&lt;path</span> <span class="na">class=</span><span class="s">&#34;path1&#34;</span> <span class="na">d=</span><span class="s">&#34;M384 384h177.106v90.782h2.532c24.64-44.194 84.958-90.782 174.842-90.782 186.946 0 221.52 116.376 221.52 267.734v308.266h-184.61v-273.278c0-65.184-1.334-149.026-96.028-149.026-96.148 0-110.82 70.986-110.82 144.292v278.012h-184.542v-576z&#34;</span><span class="nt">&gt;&lt;/path&gt;</span>
</span></span><span class="line"><span class="cl">  <span class="nt">&lt;path</span> <span class="na">class=</span><span class="s">&#34;path2&#34;</span> <span class="na">d=</span><span class="s">&#34;M64 384h192v576h-192v-576z&#34;</span><span class="nt">&gt;&lt;/path&gt;</span>
</span></span><span class="line"><span class="cl">  <span class="nt">&lt;path</span> <span class="na">class=</span><span class="s">&#34;path3&#34;</span> <span class="na">d=</span><span class="s">&#34;M256 224c0 53.019-42.981 96-96 96s-96-42.981-96-96c0-53.019 42.981-96 96-96s96 42.981 96 96z&#34;</span><span class="nt">&gt;&lt;/path&gt;</span>
</span></span><span class="line"><span class="cl"><span class="nt">&lt;/symbol&gt;</span>
</span></span><span class="line"><span class="cl"><span class="nt">&lt;symbol</span> <span class="na">id=</span><span class="s">&#34;icon-github&#34;</span> <span class="na">viewBox=</span><span class="s">&#34;0 0 1024 1024&#34;</span><span class="nt">&gt;</span>
</span></span><span class="line"><span class="cl">  <span class="nt">&lt;title&gt;</span>github<span class="nt">&lt;/title&gt;</span>
</span></span><span class="line"><span class="cl">  <span class="nt">&lt;path</span> <span class="na">class=</span><span class="s">&#34;path1&#34;</span> <span class="na">d=</span><span class="s">&#34;M512.008 12.642c-282.738 0-512.008 229.218-512.008 511.998 0 226.214 146.704 418.132 350.136 485.836 25.586 4.738 34.992-11.11 34.992-24.632 0-12.204-0.48-52.542-0.696-95.324-142.448 30.976-172.504-60.41-172.504-60.41-23.282-59.176-56.848-74.916-56.848-74.916-46.452-31.778 3.51-31.124 3.51-31.124 51.4 3.61 78.476 52.766 78.476 52.766 45.672 78.27 119.776 55.64 149.004 42.558 4.588-33.086 17.852-55.68 32.506-68.464-113.73-12.942-233.276-56.85-233.276-253.032 0-55.898 20.004-101.574 52.76-137.428-5.316-12.9-22.854-64.972 4.952-135.5 0 0 43.006-13.752 140.84 52.49 40.836-11.348 84.636-17.036 128.154-17.234 43.502 0.198 87.336 5.886 128.256 17.234 97.734-66.244 140.656-52.49 140.656-52.49 27.872 70.528 10.35 122.6 5.036 135.5 32.82 35.856 52.694 81.532 52.694 137.428 0 196.654-119.778 239.95-233.79 252.624 18.364 15.89 34.724 47.046 34.724 94.812 0 68.508-0.596 123.644-0.596 140.508 0 13.628 9.222 29.594 35.172 24.566 203.322-67.776 349.842-259.626 349.842-485.768 0-282.78-229.234-511.998-511.992-511.998z&#34;</span><span class="nt">&gt;&lt;/path&gt;</span>
</span></span><span class="line"><span class="cl"><span class="nt">&lt;/symbol&gt;</span></span></span></code></pre></div>
<p>Note that each symbol has a unique id, we will use this later to include the icon on any page. We can place these icons at the top of every page, just below the body tag:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-html" data-lang="html"><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">svg</span> <span class="na">style</span><span class="o">=</span><span class="s">&#34;display: none&#34;</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">  <span class="p">&lt;</span><span class="nt">defs</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">  <span class="c">&lt;!-- all your icon definitions --&gt;</span>
</span></span><span class="line"><span class="cl">  <span class="p">&lt;/</span><span class="nt">defs</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;/</span><span class="nt">svg</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c">&lt;!-- remainder of page --&gt;</span></span></span></code></pre></div>
<p>Last we need some CSS to make sure the icons display correctly. Don&rsquo;t change the width and height values, by setting them both to <code>1em</code> we can later scale the icons properly using <code>font-size</code>.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-css" data-lang="css"><span class="line"><span class="cl"><span class="p">.</span><span class="nc">svg-icon</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">  <span class="k">display</span><span class="p">:</span> <span class="kc">inline-block</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">  <span class="k">width</span><span class="p">:</span> <span class="mi">1</span><span class="kt">em</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">  <span class="k">height</span><span class="p">:</span> <span class="mi">1</span><span class="kt">em</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">  <span class="n">fill</span><span class="p">:</span> <span class="kc">currentColor</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></div>
<h2 id="using-the-icons">Using the icons</h2>
<p>The only drawback of this method is that including an icon is a bit more work than the Font Awesome approach. But, when you&rsquo;ll get used to it you won&rsquo;t see the difference. Instead of the convenient <code>fa fa-icon</code> classes we use an inline svg element:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-html" data-lang="html"><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">svg</span> <span class="na">class</span><span class="o">=</span><span class="s">&#34;svg-icon&#34;</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">  <span class="p">&lt;</span><span class="nt">use</span> <span class="na">xlink:href</span><span class="o">=</span><span class="s">&#34;#icon-github&#34;</span><span class="p">&gt;&lt;/</span><span class="nt">use</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;/</span><span class="nt">svg</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c">&lt;!-- Examples showing larger font sizes: --&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">span</span> <span class="na">style</span><span class="o">=</span><span class="s">&#34;font-size: 1em;&#34;</span><span class="p">&gt;&lt;</span><span class="nt">svg</span> <span class="na">class</span><span class="o">=</span><span class="s">&#34;svg-icon&#34;</span><span class="p">&gt;&lt;</span><span class="nt">use</span> <span class="na">xlink:href</span><span class="o">=</span><span class="s">&#34;#icon-github&#34;</span><span class="p">&gt;&lt;/</span><span class="nt">use</span><span class="p">&gt;&lt;/</span><span class="nt">svg</span><span class="p">&gt;&lt;/</span><span class="nt">span</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">span</span> <span class="na">style</span><span class="o">=</span><span class="s">&#34;font-size: 2em;&#34;</span><span class="p">&gt;&lt;</span><span class="nt">svg</span> <span class="na">class</span><span class="o">=</span><span class="s">&#34;svg-icon&#34;</span><span class="p">&gt;&lt;</span><span class="nt">use</span> <span class="na">xlink:href</span><span class="o">=</span><span class="s">&#34;#icon-github&#34;</span><span class="p">&gt;&lt;/</span><span class="nt">use</span><span class="p">&gt;&lt;/</span><span class="nt">svg</span><span class="p">&gt;&lt;/</span><span class="nt">span</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">span</span> <span class="na">style</span><span class="o">=</span><span class="s">&#34;font-size: 3em;&#34;</span><span class="p">&gt;&lt;</span><span class="nt">svg</span> <span class="na">class</span><span class="o">=</span><span class="s">&#34;svg-icon&#34;</span><span class="p">&gt;&lt;</span><span class="nt">use</span> <span class="na">xlink:href</span><span class="o">=</span><span class="s">&#34;#icon-github&#34;</span><span class="p">&gt;&lt;/</span><span class="nt">use</span><span class="p">&gt;&lt;/</span><span class="nt">svg</span><span class="p">&gt;&lt;/</span><span class="nt">span</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c">&lt;!-- Example with color: --&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">span</span> <span class="na">style</span><span class="o">=</span><span class="s">&#34;color: darkred&#34;</span><span class="p">&gt;&lt;</span><span class="nt">svg</span> <span class="na">class</span><span class="o">=</span><span class="s">&#34;svg-icon&#34;</span><span class="p">&gt;&lt;</span><span class="nt">use</span> <span class="na">xlink:href</span><span class="o">=</span><span class="s">&#34;#icon-github&#34;</span><span class="p">&gt;&lt;/</span><span class="nt">use</span><span class="p">&gt;&lt;/</span><span class="nt">svg</span><span class="p">&gt;&lt;/</span><span class="nt">span</span><span class="p">&gt;</span></span></span></code></pre></div>
<p>If you added everything the snippet above will show the following:</p>
<p><span style="font-size: 1em;"><svg class="svg-icon"><use xlink:href="#icon-gh"></use></svg></span>
<span style="font-size: 2em;"><svg class="svg-icon"><use xlink:href="#icon-gh"></use></svg></span>
<span style="font-size: 3em;"><svg class="svg-icon"><use xlink:href="#icon-gh"></use></svg></span>
<span style="color: darkred"><svg class="svg-icon"><use xlink:href="#icon-gh"></use></svg></span></p>
<p>Additionally, you can apply many of the same CSS effects to these SVG icons as you would with normal text. Only text-specific things such as <code>text-decoration</code> or <code>font-style</code> won&rsquo;t work.</p>
<h2 id="conclusion">Conclusion</h2>
<p>I really loved working with FontAwesome in previous projects. But, for this blog, replacing the icons with their SVG counterpart made a large difference in performance. For (small) blogs such a change can be done very quickly as the set of used icons is often limited. For larger applications this could result in a larger rewrite of your codebase. But, given all the benefits I wouldn&rsquo;t be surprised if more websites would do the same. To quote <a href="https://github.com/blog/2112-delivering-octicons-with-svg">Github</a> :</p>
<blockquote>
<p>By switching from icon fonts, we can serve our icons more easily, more quickly, and more accessibly. And they look better. Enjoy.</p>
</blockquote>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
