<?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 Thomas Kluiters on Medium]]></title>
        <description><![CDATA[Stories by Thomas Kluiters on Medium]]></description>
        <link>https://medium.com/@thomas.kluiters?source=rss-b246e4de7380------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*TpkLx-yir4WIickN.jpg</url>
            <title>Stories by Thomas Kluiters on Medium</title>
            <link>https://medium.com/@thomas.kluiters?source=rss-b246e4de7380------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 03:20:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thomas.kluiters/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[The Battle for Kilobytes in JavaScript]]></title>
            <link>https://medium.com/better-programming/battle-of-the-kilobytes-squeezing-out-every-little-byte-in-web-applications-for-the-greater-good-98489143ab5f?source=rss-b246e4de7380------2</link>
            <guid isPermaLink="false">https://medium.com/p/98489143ab5f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[preact]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Thomas Kluiters]]></dc:creator>
            <pubDate>Wed, 02 Sep 2020 22:22:07 GMT</pubDate>
            <atom:updated>2020-09-08T17:44:00.760Z</atom:updated>
            <content:encoded><![CDATA[<h4>Squeezing out every little byte in web apps for speed and the greater good</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*1DVbm5ROPVld5vRz" /><figcaption>Photo by <a href="https://unsplash.com/photos/dQkXoqQLn40">Vlad Tchompalov</a> on <a href="https://unsplash.com/">Unsplash</a>.</figcaption></figure><p>I often find myself browsing the internet on my older phone, waiting endlessly for applications to load only to click on the wrong button because some other HTML element rendered itself slightly later than the button. Pushing the button down revealed some other link.</p><p>Why can’t web pages be... lighter?</p><p>There are many ways in which you can speed up page render speeds. One particular way I’d like to focus on today is reducing the amount of <em>stuff</em> we send to our poor visitors.</p><p>While size does matter, I still want to use a cutting-edge component library. I have recently been favoring <a href="https://preactjs.com/">Preact</a> over other component libraries.</p><p>The nice advantage of Preact is that it is tiny! When comparing React’s 109kb (34.8 kb gzipped) size to Preact’s 3kb size, it’s quite obvious that Preact is an attractive option.</p><p>Preact does come with the drawback that it does not offer as many features as React does and it takes a little while to get used to, but I have found this not a reason to be deterred.</p><p>Now that we’ve settled on our component library, I’d like to introduce you to a concept that has recently been gaining a bit more traction: CSS-only frameworks. The great thing about CSS-only frameworks is that they’re extremely lightweight, and when built well, they allow you to easily customize the CSS framework to tailor to your specific needs.</p><p>My favorite CSS framework by far is <a href="https://bulma.io/">Bulma</a>. It is lightweight, well documented, and infinitely customizable.</p><p>Lastly, I’d like to mention that I’m a huge fan of <a href="https://www.typescriptlang.org/">TypeScript</a> and will be using TypeScript in this article.</p><p>Enough talk! Let’s build an example project! Let’s install the preact-cli to help us create our first project:</p><pre>npm i -g preact-cli</pre><p>With Preact CLI installed, let’s create a new TypeScript project called my-app:</p><pre>preact create typescript my-app</pre><p>We can now run our app in the background by entering the following command in our terminal:</p><pre>npm run dev</pre><p>Our next step will be acquiring Bulma and installing it:</p><pre>npm install bulma node-sass sass-loader --save-dev</pre><p>Normally, you would want to save these kinds of dependencies as an ordinary “dependency,” as you’d just include the entire CSS file. However, we’re going to be using a CSS loader to only load the CSS that we actually need for our application, slimming down our app as much as we can!</p><p>We will also need a Sass loader to be able to import parts of the Bulma library.</p><p>Let’s create a file under the src/style directory, call it index.scss, and import the necessary CSS to add a Bulma-themed button to the front page of our web application:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8666916d71655369abd2f62c13642b1b/href">https://medium.com/media/8666916d71655369abd2f62c13642b1b/href</a></iframe><p>Also, make sure to change the first line of index.js under src to import “./style/index.scss”.</p><p>After looking over <a href="https://bulma.io/documentation/elements/button/">the documentation on buttons</a> for Bulma, it seems like we’ll have to create a simple &lt;button&gt; element and assign it to the button class. Sounds easy enough! Let’s change our code in src/routes/home/index.tsx to:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fff3565987bef1ebf28f6895234c921a/href">https://medium.com/media/fff3565987bef1ebf28f6895234c921a/href</a></iframe><p>Switch back to your browser and you should be able to see a beautiful button appearing!</p><p>Time to put our application to the test. Let’s run the following command to truly squeeze out the smallest blob of code we can think of:</p><pre>preact build --no-sw --no-ssr --no-esm<br>serve -s build</pre><p>Let’s open up Lighthouse and see the difference between an application that has exactly the same code (replacing preact-router with react-router-dom ):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*MY-hFLEnzd9utEgra40e0w.png" /><figcaption>Preact and Bulma: A total size of 23.7kb!</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*OwTw4sB-ZLjsBRDQu02Mzw.png" /><figcaption>The same application in React. Still small, but three times as large!</figcaption></figure><p>Neat! It might not seem like much, but a 50kb difference could mean quite a bit on very slow connections or phones.</p><p>I hope you were able to learn something about CSS-only frameworks, Preact, and creating smaller web applications while still enjoying the experience of component libraries such as Preact. As always, feel free to reach out if you have any questions!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98489143ab5f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/battle-of-the-kilobytes-squeezing-out-every-little-byte-in-web-applications-for-the-greater-good-98489143ab5f">The Battle for Kilobytes in JavaScript</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Minuscule Docker Images That Could]]></title>
            <link>https://medium.com/better-programming/the-minuscule-docker-images-that-could-22bac9ed950b?source=rss-b246e4de7380------2</link>
            <guid isPermaLink="false">https://medium.com/p/22bac9ed950b</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Thomas Kluiters]]></dc:creator>
            <pubDate>Fri, 26 Jul 2019 13:21:00 GMT</pubDate>
            <atom:updated>2019-07-29T17:47:48.292Z</atom:updated>
            <content:encoded><![CDATA[<h4>Automagically create minuscule docker images based on your needs</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9n8TVjkesFxTqhC2m7sUrg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@ksharkovski?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Kirill Sharkovski</a> on <a href="https://unsplash.com/search/photos/different-sizes?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>A Weird Obsession</h3><p>In the last couple of months, I have found myself obsessed with one simple problem. How small can we make a Docker image while still being able to run our applications?</p><p>I know, it’s a weird thing to be obsessed with.</p><p>Before we dive into the details and start getting technical, I’d like to explain why this problem is interesting to me and how it could be relevant to you.</p><h3>Why Size Matters</h3><p>By reducing the number of things that we put inside our Docker image we are reducing the number of possible security vulnerabilities lingering around in our Docker container. Additionally, it enables the images to just be much cleaner, only containing what they need to make the application run.</p><p>There is also the minor advantage of the images downloading a bit quicker, but in my opinion, this is not too important.</p><p><em>Note: Alpine images are already very small and will probably be sufficient if you care about size.</em></p><h3>Distroless Images</h3><p>The <a href="https://github.com/GoogleContainerTools/distroless">Distroless project</a> offers a collection of “distroless” base images which do not contain any package managers, shells, or other utilities you’d normally expect to have in your command line. As a result of this, we cannot use package managers like pip<em> </em>and<em> </em>apt:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea42cf902fabc6116b44ef19d6a3eb76/href">https://medium.com/media/ea42cf902fabc6116b44ef19d6a3eb76/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04e5b073d99c24a63cd1ea540a612b9e/href">https://medium.com/media/04e5b073d99c24a63cd1ea540a612b9e/href</a></iframe><p>Typically this problem would be solved through multi-stage builds:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b00ad315d13289eca27378d136f1628/href">https://medium.com/media/2b00ad315d13289eca27378d136f1628/href</a></iframe><p>The size of the resulting image is 130MB. Not too bad! For comparison, the default Python image is 929MB, the slimmed-down variant, 3.7-slim, is 179MB, the alpine image, 3.7-alpine, is 98.6MB, and finally, the distroless base image used in the example is 50.9MB.</p><p>Now, one may correctly point out that in the previous example we are copying the entire /usr/local/lib/python3.7/site-packages directory, which may contain dependencies we do not need. Though, it is clear that the difference in the size of all existing Python base images varies.</p><p><em>As of writing this, Google distroless does not support many images: Java and Python are experimental and Python only exists for 2.7 and 3.5.</em></p><h3>Minuscule Images</h3><p>Back to my obsession with creating small images.</p><p>Originally, I wanted to see how these distroless images were built. The distroless project makes use of Google’s bazel build tool. However, setting up Bazel and writing my own images required a bit of work (and let’s be honest, re-inventing the wheel can be extremely fun and educative). I wanted to be able to create smaller images more easily, the act of making an image should be extremely simple, it should be <em>trivial</em>. No configuration files, just one line in the terminal: just build an image for &lt;application&gt;.</p><p>Now, if you want to build your own images, you should be aware of a unique docker image: scratch . Scratch is an ‘empty’ image — it does not contain any files (though, it is a whopping 77 bytes by default).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4e129a4d6662e721c32ef2101ae590a/href">https://medium.com/media/d4e129a4d6662e721c32ef2101ae590a/href</a></iframe><p>The idea of a scratch image is that we can copy any dependencies in from our host machine and either use these dependencies inside the Dockerfile (like copying in apt and installing dependencies from scratch) or later when the Docker image is materialized. This gives us <em>full</em> control of what we put inside our Docker container, and thus, also full control of the size of the image.</p><p>Now, we need some way to gather these dependencies. Existing tools like apt allow you to download packages but they are only constrained to your current machine and, after all, would not support Windows or MacOS.</p><p>So, I set out to build my own tool that would be able to automagically build the smallest possible base image to run any application. I would use Ubuntu/Debian packages, fetch them (accessing the package servers directly), and recursively find their dependencies. The tool should always download the latest version stable version of a package, mitigating as many security risks as possible.</p><p>I called the tool fetchy, because… it fetches… things… The tool works through a command line interface, though, it also offers an API.</p><p>In order to build an image with fetchy (let’s take Python here), all you have to do is use the CLI as follows: fetchy dockerize python. You may be prompted for your target operating system and codename, as fetchy can only use Debian and Ubuntu-based packages for now.</p><p>Now, optionally, some dependencies may not be used at all (in our context), and we could also exclude them. For example: Python depends on perl, though, Python will run fine without Perl installed.</p><h3>Results</h3><p>The Python image produced when running fetchy dockerize python3.5 is only 35MB (I do believe it can be slimmed down even more, for the future perhaps?), it seems like we have managed to shave off 15MB from the distroless image.</p><p>You can view all the images produced so far here: <a href="https://hub.docker.com/r/fetchy/python">https://hub.docker.com/r/fetchy/</a></p><p>The project can be found here: <a href="https://github.com/ThomasKluiters/fetchy">https://github.com/ThomasKluiters/fetchy</a></p><p>If you’re missing features, simply create an issue and I’d be happy to help you out :). Furthermore — I am currently working on integrating other package managers into fetchy — this way multi-stage builds are no longer required.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22bac9ed950b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/the-minuscule-docker-images-that-could-22bac9ed950b">The Minuscule Docker Images That Could</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>