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 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <!doctype html><!-- This is a valid HTML5 document. -->
  2. <!-- Screen readers, SEO, extensions and so on. -->
  3. <html lang="en">
  4. <!-- Has to be within the first 1024 bytes, hence before the `title` element
  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>Capo.js: A five minute web performance boost (archive) — David Larlet</title>
  13. <meta name="description" content="Publication mise en cache pour en conserver une trace.">
  14. <!-- That good ol' feed, subscribe :). -->
  15. <link rel="alternate" type="application/atom+xml" title="Feed" href="/david/log/">
  16. <!-- Generated from https://realfavicongenerator.net/ such a mess. -->
  17. <link rel="apple-touch-icon" sizes="180x180" href="/static/david/icons2/apple-touch-icon.png">
  18. <link rel="icon" type="image/png" sizes="32x32" href="/static/david/icons2/favicon-32x32.png">
  19. <link rel="icon" type="image/png" sizes="16x16" href="/static/david/icons2/favicon-16x16.png">
  20. <link rel="manifest" href="/static/david/icons2/site.webmanifest">
  21. <link rel="mask-icon" href="/static/david/icons2/safari-pinned-tab.svg" color="#07486c">
  22. <link rel="shortcut icon" href="/static/david/icons2/favicon.ico">
  23. <meta name="msapplication-TileColor" content="#f7f7f7">
  24. <meta name="msapplication-config" content="/static/david/icons2/browserconfig.xml">
  25. <meta name="theme-color" content="#f7f7f7" media="(prefers-color-scheme: light)">
  26. <meta name="theme-color" content="#272727" media="(prefers-color-scheme: dark)">
  27. <!-- Is that even respected? Retrospectively? What a shAItshow…
  28. https://neil-clarke.com/block-the-bots-that-feed-ai-models-by-scraping-your-website/ -->
  29. <meta name="robots" content="noai, noimageai">
  30. <!-- Documented, feel free to shoot an email. -->
  31. <link rel="stylesheet" href="/static/david/css/style_2021-01-20.css">
  32. <!-- See https://www.zachleat.com/web/comprehensive-webfonts/ for the trade-off. -->
  33. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  34. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  35. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  36. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  37. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  38. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  39. <script>
  40. function toggleTheme(themeName) {
  41. document.documentElement.classList.toggle(
  42. 'forced-dark',
  43. themeName === 'dark'
  44. )
  45. document.documentElement.classList.toggle(
  46. 'forced-light',
  47. themeName === 'light'
  48. )
  49. }
  50. const selectedTheme = localStorage.getItem('theme')
  51. if (selectedTheme !== 'undefined') {
  52. toggleTheme(selectedTheme)
  53. }
  54. </script>
  55. <meta name="robots" content="noindex, nofollow">
  56. <meta content="origin-when-cross-origin" name="referrer">
  57. <!-- Canonical URL for SEO purposes -->
  58. <link rel="canonical" href="https://frontendmasters.com/blog/capo-js-a-five-minute-web-performance-boost/">
  59. <body class="remarkdown h1-underline h2-underline h3-underline em-underscore hr-center ul-star pre-tick" data-instant-intensity="viewport-all">
  60. <article>
  61. <header>
  62. <h1>Capo.js: A five minute web performance boost</h1>
  63. </header>
  64. <nav>
  65. <p class="center">
  66. <a href="/david/" title="Aller à l’accueil"><svg class="icon icon-home">
  67. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-home"></use>
  68. </svg> Accueil</a> •
  69. <a href="https://frontendmasters.com/blog/capo-js-a-five-minute-web-performance-boost/" title="Lien vers le contenu original">Source originale</a>
  70. <br>
  71. Mis en cache le 2024-03-03
  72. </p>
  73. </nav>
  74. <hr>
  75. <p>You want a quick web performance win at work that’s sure to get you a promotion? Want it to only take five minutes? Then I got you.</p>
  76. <figure class="wp-block-image size-full"><img decoding="async" src="https://i0.wp.com/frontendmasters.com/blog/wp-content/uploads/2024/02/Untitled.png?resize=519%2C97&amp;ssl=1" alt="Screenshot of the Capo.js console output showing rows of colored rectangles for the Actual order and Sorted order of elements in the head." class="wp-image-1090" srcset="https://i0.wp.com/frontendmasters.com/blog/wp-content/uploads/2024/02/Untitled.png?w=519&amp;ssl=1 519w, https://i0.wp.com/frontendmasters.com/blog/wp-content/uploads/2024/02/Untitled.png?resize=300%2C56&amp;ssl=1 300w" sizes="(max-width: 519px) 100vw, 519px" data-recalc-dims="1"></figure>
  77. <p><a href="https://rviscomi.github.io/capo.js/">Capo.js</a> is a tool to get your <code>&lt;head&gt;</code> in order. It’s based on some <a href="https://csswizardry.com/ct/">research by Harry Roberts</a> that shows how something seemingly insignificant as the elements in your <code>&lt;head&gt;</code> tag can make your page load up to 7 seconds slower! From pragma directives, to async scripts, to stylesheets, to open graph tags, it’s easy to mess up and can have consequences. Capo.js will show you the <a href="https://rviscomi.github.io/capo.js/user/rules/">specific order of elements</a> to make your <code>&lt;head&gt;</code> and your page a little (or a lotta) bit faster.</p>
  78. <h2 class="wp-block-heading" id="toc-1"><a href="#usage" aria-hidden="true" class="aal_anchor" id="usage"><svg aria-hidden="true" class="aal_svg" version="1.1" viewbox="0 0 16 16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Usage</h2>
  79. <ol>
  80. <li>Head over to <a href="https://rviscomi.github.io/capo.js/">Capo.js homepage</a></li>
  81. <li>Install the <a href="https://chromewebstore.google.com/detail/capo-get-your-%EF%B9%A4%F0%9D%9A%91%F0%9D%9A%8E%F0%9D%9A%8A%F0%9D%9A%8D%EF%B9%A5/ohabpnaccigjhkkebjofhpmebofgpbeb">Capo.js Chrome Extension</a> (you can also use it as a DevTools Snippet or bookmarklet)</li>
  82. <li>Run Capo.js</li>
  83. </ol>
  84. <p>Capo.js will log two colored bar charts in your JS console; your “Actual” <code>&lt;head&gt;</code> order and a “Sorted” <code>&lt;head&gt;</code> order. You can expand each chart to see more details. If you see a big gray bar in the middle of your “Actual” bar chart, then you’re leaving some quick wins on the table. The “Sorted” dropdown will show you the corrected order and even give you the code. But in the real world you probably need to futz with a layout template or your <code>_header.php</code> to get it reorganized.</p>
  85. <p>Installing Capo.js takes about a minute, rearranging your <code>&lt;head&gt;</code> takes another minute. Honestly the longest part is making the Pull Request.</p>
  86. <h2 class="wp-block-heading" id="toc-2"><a href="#editor-intervention" aria-hidden="true" class="aal_anchor" id="editor-intervention"><svg aria-hidden="true" class="aal_svg" version="1.1" viewbox="0 0 16 16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>EDITOR INTERVENTION</h2>
  87. <p>[Chris busts through the door.]</p>
  88. <p>OK fine Dave, I’ll give it a shot right here on Boost itself. </p>
  89. <p>I installed the Chrome Extension and ran it and got this little popup:</p>
  90. <figure class="wp-block-image size-large"><img decoding="async" src="https://i0.wp.com/frontendmasters.com/blog/wp-content/uploads/2024/02/before.png?resize=1024%2C187&amp;ssl=1" alt='"Before" sort order, scattered rectangles of various colors' class="wp-image-1095" srcset="https://i0.wp.com/frontendmasters.com/blog/wp-content/uploads/2024/02/before.png?resize=1024%2C187&amp;ssl=1 1024w, https://i0.wp.com/frontendmasters.com/blog/wp-content/uploads/2024/02/before.png?resize=300%2C55&amp;ssl=1 300w, https://i0.wp.com/frontendmasters.com/blog/wp-content/uploads/2024/02/before.png?resize=768%2C140&amp;ssl=1 768w, https://i0.wp.com/frontendmasters.com/blog/wp-content/uploads/2024/02/before.png?w=1272&amp;ssl=1 1272w" sizes="(max-width: 1000px) 100vw, 1000px" data-recalc-dims="1"></figure>
  91. <p> At first I was a little confused, like this was some fancy code that Web Perf people immediately understand but I was out of the loop on. But actually it’s just a visualization of the order of things (top: actual, bottom: ideal). As a little UX feedback, it should say “Open your console for more information” because that’s where all the useful stuff is. </p>
  92. <p>I found it most useful to look at the “Sorted” output (which is what you <em>should</em> be doing) and then try to get my source code to match that. I think I generally did OK:</p>
  93. <figure class="wp-block-image size-large"><img loading="lazy" decoding="async" src="https://i0.wp.com/frontendmasters.com/blog/wp-content/uploads/2024/02/after.png?resize=1024%2C194&amp;ssl=1" alt='"After" sort order, scattered rectangles of various colors, slightly less scattered than the previous image' class="wp-image-1096" srcset="https://i0.wp.com/frontendmasters.com/blog/wp-content/uploads/2024/02/after.png?resize=1024%2C194&amp;ssl=1 1024w, https://i0.wp.com/frontendmasters.com/blog/wp-content/uploads/2024/02/after.png?resize=300%2C57&amp;ssl=1 300w, https://i0.wp.com/frontendmasters.com/blog/wp-content/uploads/2024/02/after.png?resize=768%2C146&amp;ssl=1 768w, https://i0.wp.com/frontendmasters.com/blog/wp-content/uploads/2024/02/after.png?w=1298&amp;ssl=1 1298w" sizes="(max-width: 1000px) 100vw, 1000px" data-recalc-dims="1"></figure>
  94. <p>I wasn’t able to get it perfect because of WordPress. A decent chunk of what goes into your <code>&lt;head&gt;</code> in WordPress comes from the output of the <code>&lt;php wp_head(); ?&gt;</code> function. I’m sure it’s technically possible to re-order output in there, but that was a more effort that I felt was worth it right at this minute.</p>
  95. <p>Take your wins, that’s what I always say.</p>
  96. </article>
  97. <hr>
  98. <footer>
  99. <p>
  100. <a href="/david/" title="Aller à l’accueil"><svg class="icon icon-home">
  101. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-home"></use>
  102. </svg> Accueil</a> •
  103. <a href="/david/log/" title="Accès au flux RSS"><svg class="icon icon-rss2">
  104. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-rss2"></use>
  105. </svg> Suivre</a> •
  106. <a href="http://larlet.com" title="Go to my English profile" data-instant><svg class="icon icon-user-tie">
  107. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-user-tie"></use>
  108. </svg> Pro</a> •
  109. <a href="mailto:david%40larlet.fr" title="Envoyer un courriel"><svg class="icon icon-mail">
  110. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-mail"></use>
  111. </svg> Email</a> •
  112. <abbr class="nowrap" title="Hébergeur : Alwaysdata, 62 rue Tiquetonne 75002 Paris, +33184162340"><svg class="icon icon-hammer2">
  113. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-hammer2"></use>
  114. </svg> Légal</abbr>
  115. </p>
  116. <template id="theme-selector">
  117. <form>
  118. <fieldset>
  119. <legend><svg class="icon icon-brightness-contrast">
  120. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-brightness-contrast"></use>
  121. </svg> Thème</legend>
  122. <label>
  123. <input type="radio" value="auto" name="chosen-color-scheme" checked> Auto
  124. </label>
  125. <label>
  126. <input type="radio" value="dark" name="chosen-color-scheme"> Foncé
  127. </label>
  128. <label>
  129. <input type="radio" value="light" name="chosen-color-scheme"> Clair
  130. </label>
  131. </fieldset>
  132. </form>
  133. </template>
  134. </footer>
  135. <script src="/static/david/js/instantpage-5.1.0.min.js" type="module"></script>
  136. <script>
  137. function loadThemeForm(templateName) {
  138. const themeSelectorTemplate = document.querySelector(templateName)
  139. const form = themeSelectorTemplate.content.firstElementChild
  140. themeSelectorTemplate.replaceWith(form)
  141. form.addEventListener('change', (e) => {
  142. const chosenColorScheme = e.target.value
  143. localStorage.setItem('theme', chosenColorScheme)
  144. toggleTheme(chosenColorScheme)
  145. })
  146. const selectedTheme = localStorage.getItem('theme')
  147. if (selectedTheme && selectedTheme !== 'undefined') {
  148. form.querySelector(`[value="${selectedTheme}"]`).checked = true
  149. }
  150. }
  151. const prefersColorSchemeDark = '(prefers-color-scheme: dark)'
  152. window.addEventListener('load', () => {
  153. let hasDarkRules = false
  154. for (const styleSheet of Array.from(document.styleSheets)) {
  155. let mediaRules = []
  156. for (const cssRule of styleSheet.cssRules) {
  157. if (cssRule.type !== CSSRule.MEDIA_RULE) {
  158. continue
  159. }
  160. // WARNING: Safari does not have/supports `conditionText`.
  161. if (cssRule.conditionText) {
  162. if (cssRule.conditionText !== prefersColorSchemeDark) {
  163. continue
  164. }
  165. } else {
  166. if (cssRule.cssText.startsWith(prefersColorSchemeDark)) {
  167. continue
  168. }
  169. }
  170. mediaRules = mediaRules.concat(Array.from(cssRule.cssRules))
  171. }
  172. // WARNING: do not try to insert a Rule to a styleSheet you are
  173. // currently iterating on, otherwise the browser will be stuck
  174. // in a infinite loop…
  175. for (const mediaRule of mediaRules) {
  176. styleSheet.insertRule(mediaRule.cssText)
  177. hasDarkRules = true
  178. }
  179. }
  180. if (hasDarkRules) {
  181. loadThemeForm('#theme-selector')
  182. }
  183. })
  184. </script>
  185. </body>
  186. </html>