A place to cache linked articles (think custom and personal wayback machine)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.html 13KB

  1. <!doctype html><!-- This is a valid HTML5 document. -->
  2. <!-- Screen readers, SEO, extensions and so on. -->
  3. <html lang="fr">
  4. <!-- Has to be within the first 1024 bytes, hence before the <title>
  5. See: https://www.w3.org/TR/2012/CR-html5-20121217/document-metadata.html#charset -->
  6. <meta charset="utf-8">
  7. <!-- Why no `X-UA-Compatible` meta: https://stackoverflow.com/a/6771584 -->
  8. <!-- The viewport meta is quite crowded and we are responsible for that.
  9. See: https://codepen.io/tigt/post/meta-viewport-for-2015 -->
  10. <meta name="viewport" content="width=device-width,initial-scale=1">
  11. <!-- Required to make a valid HTML5 document. -->
  12. <title>Building with Friction (archive) — David Larlet</title>
  13. <!-- Generated from https://realfavicongenerator.net/ such a mess. -->
  14. <link rel="apple-touch-icon" sizes="180x180" href="/static/david/icons2/apple-touch-icon.png">
  15. <link rel="icon" type="image/png" sizes="32x32" href="/static/david/icons2/favicon-32x32.png">
  16. <link rel="icon" type="image/png" sizes="16x16" href="/static/david/icons2/favicon-16x16.png">
  17. <link rel="manifest" href="/static/david/icons2/site.webmanifest">
  18. <link rel="mask-icon" href="/static/david/icons2/safari-pinned-tab.svg" color="#07486c">
  19. <link rel="shortcut icon" href="/static/david/icons2/favicon.ico">
  20. <meta name="msapplication-TileColor" content="#f0f0ea">
  21. <meta name="msapplication-config" content="/static/david/icons2/browserconfig.xml">
  22. <meta name="theme-color" content="#f0f0ea">
  23. <!-- Documented, feel free to shoot an email. -->
  24. <link rel="stylesheet" href="/static/david/css/style_2020-04-25.css">
  25. <!-- See https://www.zachleat.com/web/comprehensive-webfonts/ for the trade-off. -->
  26. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light)" crossorigin>
  27. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light)" crossorigin>
  28. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light)" crossorigin>
  29. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  30. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  31. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  32. <meta name="robots" content="noindex, nofollow">
  33. <meta content="origin-when-cross-origin" name="referrer">
  34. <!-- Canonical URL for SEO purposes -->
  35. <link rel="canonical" href="https://timkadlec.com/remembers/2020-03-18-building-with-friction/">
  36. <body class="remarkdown h1-underline h2-underline h3-underline hr-center ul-star pre-tick">
  37. <article>
  38. <h1>Building with Friction</h1>
  39. <h2><a href="https://timkadlec.com/remembers/2020-03-18-building-with-friction/">Source originale du contenu</a></h2>
  40. <p>I <a href="https://timkadlec.com/remembers/2020-01-02-making-the-right-thing-easy/">recently wrote about how important it is to make the right thing easy</a>. The opposite is also true: it’s important to make the wrong things difficult. I did allude to it in that post a little bit, but I thought it was worth calling out explicitly. It’s important to introduce some friction in our workflow to help prevent the wrong actions.</p>
  41. <p>Continuing on the health-related analogies, friction is a big part of how I manage my sweet tooth. I work by myself in a small office. Nothing is preventing me from constantly snacking on a bunch of sweets, and <em>wow</em> would I ever love to. I’m a sucker for just about anything with sugar.</p>
  42. <p>But I discovered something else about myself: I’m also kinda lazy. So I take a two-part approach. The first is to make the right thing easy. I have apples, oranges, almonds, dried cranberries, and all sorts of healthier snacking options right next to my desk. If I’m hungry, I don’t even have to move. I reach out my arm, and there they are.</p>
  43. <p>But the second part of that process is just as important. I make the wrong thing harder. I do have some sweets, but they’re tucked away in an adjacent room. It’s not difficult to get to them, but it does require more effort than the healthy alternatives right next to me. It doesn’t stop me from having sweets, but it means that reaching for that chocolate involves a conscious decision to put in more work than if I decide to have an apple. It’s just enough friction to change the way I snack.</p>
  44. <p>A lot of modern workflow improvements have been around <em>removing</em> friction. We want to make it easier to deploy rapidly. Tools like npm make it <em>very</em> easy to gain access to any and all modules we could think of. Tag management enables folks to very quickly add another third-party service.</p>
  45. <p>All of these things, on the surface, provide some value, but the consequences are tremendous. Because these processes remove friction, they don’t ever really give us a chance to pause and consider what we’re doing.</p>
  46. <p>Re-introducing some healthy friction, some moments of pause, in our processes is critical to ensuring a higher level of quality overall.</p>
  47. <p>For example, let’s tackle the trouble with <a href="https://www.npmjs.com/">npm</a>.</p>
  48. <p>npm transformed the way we build, but I don’t think anyone can argue that it hasn’t wreaked some serious havoc in the process. The ready availability of a JavaScript module for pretty much anything you can imagine has lead to security issues, accessibility concerns and overall bloat. It’s made it <em>too easy</em> to add more code to our sites without ever considering the trade-offs.</p>
  49. <p>I’m with <a href="https://twitter.com/slightlylate/status/1239404640656998400">Alex on this one</a>. Adding more code should be a very intentional decision:</p>
  50. <blockquote>
  51. <p>JavaScript should be a *deeply” intentional choice on the client. Tools that remove intentionality, whatever else they may have done for your team, probably sunk your perf battleship.</p>
  52. </blockquote>
  53. <p>Here’s an example of how we could introduce some friction into the process to help with the performance challenges by focusing on two critical points in our workflow: install and build/deploy.</p>
  54. <h2 id="during-install">During install</h2>
  55. <p>The first thing we can do is introduce some friction when we first install a script. After all, the easiest issues to fix are the ones that haven’t happened yet.</p>
  56. <p>I like <a href="https://github.com/AdrieanKhisbe/bundle-phobia-cli#bundle-phobia-install"><code>bundle-phobia-install</code></a> for this. <code>bundle-phobia-install</code> is a wrapper around <code>npm install</code> that uses information from <a href="https://bundlephobia.com/">Bundlephobia</a> to conditionally install npm modules. It does this by comparing the size of the package against some predetermined limits. It defaults to a size limit of 100kB overall (as in, the total of all dependencies), but you can configure that however you would like.</p>
  57. <p>You can also set up limits on individual packages.</p>
  58. <p>For example, the following settings (configured in a <code>package.json</code> file) would ensure that no individual package with a size of over 20kB could be installed, and that the total size of all dependencies can be no more than 100kB.</p>
  59. <div class="highlight"><pre><code class="language-javascript" data-lang="javascript">...
  60. <span>"bundle-phobia"</span><span>:</span> {
  61. <span>"max-size"</span><span>:</span> <span>"20kB"</span>,
  62. <span>"max-overall-size"</span><span>:</span> <span>"100kB"</span>
  63. },
  64. ...
  65. </code></pre></div>
  66. <p>Now, if we were to try to install, say, <code>lodash</code>, the install would fail because <code>lodash</code> exceeds our individual package size limit.</p>
  67. <figure class="banner">
  68. <img src="https://timkadlec.com/images/friction-bundle-phobia.png" alt="Running bundle-phobia-install instead of npm install lets us enforce size limits on npm modules, preventing us from adding significantly heavy dependencies to our site."/> <figcaption>
  69. <p>Running <code>bundle-phobia-install</code> instead of <code>npm install</code> lets us enforce size limits on npm modules, preventing us from adding significantly heavy dependencies to our site.</p>
  70. </figcaption>
  71. </figure>
  72. <p>You could still install <code>lodash</code>, but that now requires you to run <code>bundle-phobia-install</code> with the interactive flag (<code>-i</code>) and manually approve the install despite the fact that it exceeds your limits. It turns an unconscious decision into a conscious one.</p>
  73. <h2 id="during-build-deploy">During build/deploy</h2>
  74. <p>By having some friction on the install process, we help to provide a better base for size of our JavaScript. It’s still critical to put some friction on the build and deploy process, though. For one, our install approach is only limiting npm modules, not really our own code. We also don’t really know the exact shape of our bundles at install—that comes later.</p>
  75. <p>For webpack-driven projects, you can take advantage of webpack’s <a href="https://webpack.js.org/configuration/performance/">performance hints</a>. There are two hints available to us: <code>performance.maxEntrypointSize</code> and <code>performance.maxAssetSize</code>. <code>performance.maxEntrypointSize</code> lets us set a limit for all webpack produced assets for a given route. <code>performance.maxAssetSize</code> lets us set a limit for any individual webpack produced assets.</p>
  76. <p>By default, the hints are just that—hints. They show up as warnings but don’t do anything concrete. You can change that by setting the <code>peformance.hints</code> property to <code>error</code>.</p>
  77. <p>So, given the following configuration, webpack would throw errors whenever an individual asset exceeds 100kB or all total assets for a given route exceed 150kB.</p>
  78. <div class="highlight"><pre><code class="language-javascript" data-lang="javascript"><span>module</span>.<span>exports</span> <span>=</span> {
  79. <span>//...
  80. </span><span/> <span>performance</span><span>:</span> {
  81. <span>hints</span><span>:</span> <span>'error'</span>,
  82. <span>maxEntrypointSize</span><span>:</span> <span>100000</span>,
  83. <span>maxAssetSize</span><span>:</span> <span>150000</span>
  84. }
  85. };
  86. </code></pre></div>
  87. <figure class="banner">
  88. <img src="https://timkadlec.com/images/friction-webpack.png" alt="webpack&amp;rsquo;s performance hints let us throw errors if individual assets are too large, or if all assets for a given route get too heavy."/> <figcaption>
  89. <p>webpack’s performance hints let us throw errors if individual assets are too large, or if all assets for a given route get too heavy.</p>
  90. </figcaption>
  91. </figure>
  92. <p>If you’re not using webpack, or if you are and still want to augment these hints, we can also introduce some bundle size checking at the pull request or deploy levels. <a href="https://github.com/siddharthkp/bundlesize">Bundlesize</a> is a common choice here.</p>
  93. <p>With Bundlesize, we setup maximum sizes for each bundle we want to track. Then we can run Bundlesize against those limits on every pull request or during our continuous integration process to stop us from deploying if any of those bundle sizes have been exceeded.</p>
  94. <figure class="banner">
  95. <img src="https://timkadlec.com/images/friction-bundlesize.png" alt="Bundlesize will check each bundle against the limits we set so that we can break the build if any of those limits are exceeded."/> <figcaption>
  96. <p>Bundlesize will check each bundle against the limits we set so that we can break the build if any of those limits are exceeded.</p>
  97. </figcaption>
  98. </figure>
  99. <h2 id="building-with-friction">Building with friction</h2>
  100. <p>Healthy friction in our processes, paired with automation and reporting where appropriate, can have a substantial impact on what we ship. When we force ourselves to take these moments to consider the implications of what we’re about to add to our codebase, when we make it hard to add more bloat to our applications by default, we not only change the way we build, but we change the way we <em>think</em> about building. It’s the observer effect applied to the way we code.</p>
  101. <p>When we have to consider the weight of every module we add to our project (or which vulnerabilities are included or what accessibility concerns they bring along), we start to inherently pay a little more attention to at least a part of performance every single day. It won’t magically fix all our performance woes by itself, but it certainly gets us pointed in the right direction.</p>
  102. </article>
  103. <hr>
  104. <footer>
  105. <p>
  106. <a href="/david/" title="Aller à l’accueil">🏠</a> •
  107. <a href="/david/log/" title="Accès au flux RSS">🤖</a> •
  108. <a href="http://larlet.com" title="Go to my English profile" data-instant>🇨🇦</a> •
  109. <a href="mailto:david%40larlet.fr" title="Envoyer un courriel">📮</a> •
  110. <abbr title="Hébergeur : Alwaysdata, 62 rue Tiquetonne 75002 Paris, +33184162340">🧚</abbr>
  111. </p>
  112. </footer>
  113. <script src="/static/david/js/instantpage-3.0.0.min.js" type="module" defer></script>
  114. </body>
  115. </html>