fix: missing css explainer

This commit is contained in:
Cory Dransfeldt 2023-06-07 13:31:10 -07:00
parent c384fa7ea1
commit bca69910e5
No known key found for this signature in database
5 changed files with 26 additions and 13 deletions

View file

@ -60,7 +60,6 @@ ELEVENTY_PRODUCTION=true eleventy && NODE_ENV=production npx tailwindcss -i ./ta
The site include's Prism for code syntax highlighting and this is embedded and minified in the `<head>` of each page at build time:
{% raw %}
```liquid
{% capture css %}
{% include "../assets/styles/prism.css" %}
@ -69,9 +68,16 @@ The site include's Prism for code syntax highlighting and this is embedded and m
{{ css | cssmin }}
</style>
```
{% endraw %}
This is made possible by leveraging CleanCSS in (you guessed it) `.eleventy.js`:
{% raw %}
```javascript
const CleanCSS = require('clean-css')
...
// css filters
eleventyConfig.addFilter('cssmin', (code) => new CleanCSS({}).minify(code).styles)
```
{% endraw %}
## Minify HTML output
Final HTML output for the site is minified when it's built using `@sherby/eleventy-plugin-files-minifier` which, [per the docs](https://www.npmjs.com/package/@sherby/eleventy-plugin-files-minifier):
@ -93,7 +99,6 @@ module.exports = function (eleventyConfig) {
Finally (and this is something that took me longer than it should have to do), we optimize images at build time using `@11ty/eleventy-image`, defining a shortcode in `.eleventy.js` as follows:
{% raw %}
```javascript
// image shortcode
eleventyConfig.addShortcode('image', async function (src, alt, css, sizes, loading) {
@ -115,15 +120,12 @@ eleventyConfig.addShortcode('image', async function (src, alt, css, sizes, loadi
return Image.generateHTML(metadata, imageAttributes)
})
```
{% endraw %}
This is most impactful on [my now page](https://coryd.dev/now) which is populated with quite a few images and, when used, looks something like this:
{% raw %}
```liquid
{% image artistImg, artistName, 'rounded-lg', '225px', 'eager' %}
```
{% endraw %}
For this page in particular, the images that are rendered above the fold are set to load as `eager` to mitigate performance impacts related to [too much lazy loading](https://web.dev/lcp-lazy-loading/). These images are fetched from caches hosted at [Bunny.net](https://bunny.net/?ref=revw3mehej) when the site is built.