jekyll_picture_tag 1.11.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.envrc +4 -0
- data/.github/workflows/code-checks.yml +33 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +31 -3
- data/.ruby-version +1 -1
- data/docs/.envrc +2 -0
- data/docs/Gemfile +4 -2
- data/docs/Gemfile.lock +14 -12
- data/docs/_config.yml +6 -10
- data/docs/devs/contributing/code.md +54 -0
- data/docs/devs/contributing/docs.md +31 -0
- data/docs/devs/contributing/index.md +15 -0
- data/docs/devs/contributing/setup.md +33 -0
- data/docs/devs/contributing/testing.md +23 -0
- data/docs/devs/index.md +7 -0
- data/docs/devs/releases.md +118 -0
- data/docs/index.md +67 -31
- data/docs/logo.png +0 -0
- data/docs/logo.svg +880 -0
- data/docs/users/configuration/directories.md +34 -0
- data/docs/users/configuration/disable.md +24 -0
- data/docs/users/configuration/fast_build.md +28 -0
- data/docs/users/configuration/ignore_missing.md +23 -0
- data/docs/users/configuration/index.md +29 -0
- data/docs/users/configuration/kramdown_fix.md +20 -0
- data/docs/users/configuration/suppress_warnings.md +16 -0
- data/docs/users/configuration/urls.md +69 -0
- data/docs/users/getting_started.md +55 -0
- data/docs/users/index.md +7 -0
- data/docs/users/installation.md +32 -0
- data/docs/users/liquid_tag/argument_reference/alternate_images.md +18 -0
- data/docs/users/liquid_tag/argument_reference/attributes.md +42 -0
- data/docs/users/liquid_tag/argument_reference/base_image.md +12 -0
- data/docs/users/liquid_tag/argument_reference/crop.md +33 -0
- data/docs/users/liquid_tag/argument_reference/link.md +16 -0
- data/docs/users/liquid_tag/argument_reference/preset.md +17 -0
- data/docs/users/liquid_tag/argument_reference/readme.md +9 -0
- data/docs/users/liquid_tag/examples.md +81 -0
- data/docs/users/liquid_tag/index.md +31 -0
- data/docs/users/notes/git_lfs.md +7 -0
- data/docs/users/notes/github_pages.md +5 -0
- data/docs/users/notes/html_attributes.md +5 -0
- data/docs/users/notes/index.md +6 -0
- data/docs/users/notes/kramdown_bug.md +41 -0
- data/docs/users/notes/managing_images.md +21 -0
- data/docs/{migration.md → users/notes/migration_1.md} +1 -1
- data/docs/users/notes/migration_2.md +99 -0
- data/docs/users/presets/cropping.md +60 -0
- data/docs/users/presets/default.md +32 -0
- data/docs/users/presets/examples.md +111 -0
- data/docs/users/presets/fallback_image.md +28 -0
- data/docs/users/presets/html_attributes.md +26 -0
- data/docs/users/presets/image_formats.md +21 -0
- data/docs/users/presets/image_quality.md +120 -0
- data/docs/users/presets/index.md +75 -0
- data/docs/users/presets/link_source.md +16 -0
- data/docs/users/presets/markup_formats/fragments.md +48 -0
- data/docs/users/presets/markup_formats/javascript_friendly.md +57 -0
- data/docs/users/presets/markup_formats/readme.md +43 -0
- data/docs/users/presets/markup_formats/standard_html.md +25 -0
- data/docs/users/presets/media_queries.md +36 -0
- data/docs/users/presets/nomarkdown_override.md +17 -0
- data/docs/users/presets/pixel_ratio_srcsets.md +32 -0
- data/docs/users/presets/quality_width_graph.png +0 -0
- data/docs/users/presets/width_height_attributes.md +34 -0
- data/docs/users/presets/width_srcsets.md +123 -0
- data/docs/users/presets/writing_presets.md +65 -0
- data/docs/users/tutorial.md +97 -0
- data/jekyll_picture_tag.gemspec +38 -23
- data/lib/jekyll_picture_tag.rb +11 -10
- data/lib/jekyll_picture_tag/cache.rb +64 -3
- data/lib/jekyll_picture_tag/defaults/global.rb +18 -0
- data/lib/jekyll_picture_tag/defaults/presets.rb +57 -0
- data/lib/jekyll_picture_tag/images.rb +4 -0
- data/lib/jekyll_picture_tag/images/generated_image.rb +92 -0
- data/lib/jekyll_picture_tag/images/image_file.rb +90 -0
- data/lib/jekyll_picture_tag/{img_uri.rb → images/img_uri.rb} +3 -10
- data/lib/jekyll_picture_tag/{source_image.rb → images/source_image.rb} +44 -9
- data/lib/jekyll_picture_tag/instructions.rb +70 -6
- data/lib/jekyll_picture_tag/instructions/children/config.rb +128 -0
- data/lib/jekyll_picture_tag/instructions/children/context.rb +24 -0
- data/lib/jekyll_picture_tag/instructions/children/params.rb +90 -0
- data/lib/jekyll_picture_tag/instructions/children/parsers.rb +41 -0
- data/lib/jekyll_picture_tag/instructions/children/preset.rb +182 -0
- data/lib/jekyll_picture_tag/instructions/parents/conditional_instruction.rb +69 -0
- data/lib/jekyll_picture_tag/instructions/parents/env_instruction.rb +29 -0
- data/lib/jekyll_picture_tag/output_formats/basic.rb +5 -17
- data/lib/jekyll_picture_tag/parsers.rb +5 -0
- data/lib/jekyll_picture_tag/{instructions → parsers}/arg_splitter.rb +1 -1
- data/lib/jekyll_picture_tag/parsers/configuration.rb +28 -0
- data/lib/jekyll_picture_tag/{instructions → parsers}/html_attributes.rb +1 -1
- data/lib/jekyll_picture_tag/parsers/preset.rb +43 -0
- data/lib/jekyll_picture_tag/{instructions → parsers}/tag_parser.rb +15 -12
- data/lib/jekyll_picture_tag/router.rb +35 -93
- data/lib/jekyll_picture_tag/srcsets/basic.rb +4 -10
- data/lib/jekyll_picture_tag/utils.rb +24 -20
- data/lib/jekyll_picture_tag/version.rb +1 -1
- data/readme.md +15 -13
- metadata +215 -93
- data/.travis.yml +0 -8
- data/Dockerfile +0 -9
- data/docs/_layouts/directory.html +0 -32
- data/docs/assets/style.css +0 -31
- data/docs/contributing.md +0 -109
- data/docs/example_presets.md +0 -116
- data/docs/global_configuration.md +0 -173
- data/docs/installation.md +0 -45
- data/docs/notes.md +0 -91
- data/docs/output.md +0 -63
- data/docs/presets.md +0 -391
- data/docs/releases.md +0 -70
- data/docs/usage.md +0 -157
- data/jekyll-picture-tag.gemspec +0 -52
- data/lib/jekyll-picture-tag.rb +0 -25
- data/lib/jekyll_picture_tag/cache/base.rb +0 -59
- data/lib/jekyll_picture_tag/cache/generated.rb +0 -20
- data/lib/jekyll_picture_tag/cache/source.rb +0 -19
- data/lib/jekyll_picture_tag/defaults/global.yml +0 -11
- data/lib/jekyll_picture_tag/defaults/presets.yml +0 -11
- data/lib/jekyll_picture_tag/generated_image.rb +0 -140
- data/lib/jekyll_picture_tag/instructions/configuration.rb +0 -121
- data/lib/jekyll_picture_tag/instructions/preset.rb +0 -103
- data/lib/jekyll_picture_tag/instructions/set.rb +0 -71
@@ -0,0 +1,57 @@
|
|
1
|
+
---
|
2
|
+
sort: 2
|
3
|
+
---
|
4
|
+
|
5
|
+
# Javascript Friendly
|
6
|
+
|
7
|
+
These are analogous to their plain HTML counterparts, but instead of `src`,
|
8
|
+
`srcset`, and `sizes`, you get `data-src`, `data-srcset`, and `data-sizes`. This
|
9
|
+
allows you to use javascript for things like [lazy
|
10
|
+
loading](https://github.com/verlok/lazyload).
|
11
|
+
|
12
|
+
- `data_picture`
|
13
|
+
|
14
|
+
```html
|
15
|
+
<picture>
|
16
|
+
<source data-srcset="..." data-sizes="...">
|
17
|
+
<source data-srcset="..." data-sizes="...">
|
18
|
+
(...)
|
19
|
+
<img data-src="...">
|
20
|
+
</picture>
|
21
|
+
```
|
22
|
+
|
23
|
+
- `data_img`
|
24
|
+
```html
|
25
|
+
<img data-srcset="..." data-src="..." data-sizes="...">
|
26
|
+
```
|
27
|
+
|
28
|
+
- `data_auto` - `data_picture` when needed, otherwise `data_img`.
|
29
|
+
|
30
|
+
## Special Options
|
31
|
+
|
32
|
+
The following preset settings only apply to these output formats.
|
33
|
+
|
34
|
+
- `noscript`
|
35
|
+
|
36
|
+
_Format:_ `noscript: true|false`
|
37
|
+
|
38
|
+
_Default:_ `false`
|
39
|
+
|
40
|
+
Include a basic `img` fallback within a `<noscript>` tag, giving your
|
41
|
+
non-javascript-running users something to look at.
|
42
|
+
|
43
|
+
```html
|
44
|
+
<img data-srcset="..." data-src="..." data-sizes="...">
|
45
|
+
<noscript>
|
46
|
+
<img src="..." alt="...">
|
47
|
+
</noscript>
|
48
|
+
```
|
49
|
+
|
50
|
+
- `data_sizes`
|
51
|
+
|
52
|
+
_Format:_ `data_sizes: true|false`
|
53
|
+
|
54
|
+
_Default:_ `true`
|
55
|
+
|
56
|
+
This option sets whether you would like JPT's auto-generated sizes to be returned as a
|
57
|
+
`data-sizes` attribute or a normal `sizes` attribute.
|
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
sort: 1
|
3
|
+
---
|
4
|
+
|
5
|
+
# Markup Formats
|
6
|
+
|
7
|
+
Define what format the generated text will take. Select one by setting
|
8
|
+
`markup:` in the relevant [preset]({{ site.baseurl }}/users/presets).
|
9
|
+
|
10
|
+
_Format:_ `markup: (setting)`
|
11
|
+
|
12
|
+
_Default_: `auto`
|
13
|
+
|
14
|
+
|
15
|
+
Example:
|
16
|
+
|
17
|
+
```yml
|
18
|
+
# /_data/picture.yml
|
19
|
+
|
20
|
+
markup_presets:
|
21
|
+
my_preset:
|
22
|
+
markup: data_auto
|
23
|
+
```
|
24
|
+
|
25
|
+
## Valid options:
|
26
|
+
|
27
|
+
### Standard HTML:
|
28
|
+
- `auto` - default
|
29
|
+
- `picture`
|
30
|
+
- `img`
|
31
|
+
|
32
|
+
### Javascript Friendly:
|
33
|
+
- `data_auto`
|
34
|
+
- `data_picture`
|
35
|
+
- `data_img`
|
36
|
+
|
37
|
+
### Fragments:
|
38
|
+
- `direct_url`
|
39
|
+
- `naked_srcset`
|
40
|
+
|
41
|
+
## Reference:
|
42
|
+
|
43
|
+
{% include list.liquid %}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
---
|
2
|
+
sort: 1
|
3
|
+
---
|
4
|
+
|
5
|
+
# Standard HTML
|
6
|
+
|
7
|
+
- **`picture`** - `<picture>` element surrounding a `<source>` tag for each required srcset, and a
|
8
|
+
fallback `<img>`:
|
9
|
+
|
10
|
+
```html
|
11
|
+
<picture>
|
12
|
+
<source srcset="..." sizes="..." media="..." type="...">
|
13
|
+
<source srcset="..." sizes="..." media="..." type="...">
|
14
|
+
(...)
|
15
|
+
<img src="...">
|
16
|
+
</picture
|
17
|
+
```
|
18
|
+
|
19
|
+
- **`img`** - a single `<img>` tag with a `srcset` entry:
|
20
|
+
|
21
|
+
```html
|
22
|
+
<img src="..." srcset="..." sizes="..." alt="..." width="..." height="...">
|
23
|
+
```
|
24
|
+
|
25
|
+
- **`auto`** - Supply an img tag when you have only one srcset, otherwise supply a picture tag.
|
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
sort: 3
|
3
|
+
---
|
4
|
+
|
5
|
+
# Media Queries
|
6
|
+
|
7
|
+
Jekyll Picture Tag handles media queries by letting you define them by name in
|
8
|
+
`_data/picture.yml`, and then referencing that name whenever you need it.
|
9
|
+
|
10
|
+
_Format:_
|
11
|
+
|
12
|
+
```yaml
|
13
|
+
# _data/picture.yml
|
14
|
+
|
15
|
+
media_queries:
|
16
|
+
(name): (css media query)
|
17
|
+
(name): (css media query)
|
18
|
+
(...)
|
19
|
+
|
20
|
+
```
|
21
|
+
|
22
|
+
_Example:_
|
23
|
+
|
24
|
+
```yaml
|
25
|
+
# _data/picture.yml
|
26
|
+
|
27
|
+
media_queries:
|
28
|
+
mobile: "max-width: 600px"
|
29
|
+
tablet: "max-width: 800px"
|
30
|
+
ultrawide: "min-width: 1400px"
|
31
|
+
```
|
32
|
+
|
33
|
+
They are used in a few different places: specifying alternate source images in
|
34
|
+
your liquid tag, building the 'sizes' attribute within your presets, and in a
|
35
|
+
few configuration settings. Quotes are recommended, because yml gets confused by
|
36
|
+
colons.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
sort: 13
|
3
|
+
---
|
4
|
+
|
5
|
+
# Nomarkdown Override
|
6
|
+
|
7
|
+
_Format:_ `nomarkdown: (true|false)`
|
8
|
+
|
9
|
+
_Example:_ `nomarkdown: false`
|
10
|
+
|
11
|
+
_Default:_ `nil`
|
12
|
+
|
13
|
+
Hard setting for `{::nomarkdown}` tags, overrides both autodetection and the
|
14
|
+
global setting in `_config.yml`.
|
15
|
+
|
16
|
+
See this [note]({{ site.baseurl }}/users/notes/kramdown_bug) for a detailed
|
17
|
+
explanation.
|
@@ -0,0 +1,32 @@
|
|
1
|
+
---
|
2
|
+
sort: 6
|
3
|
+
---
|
4
|
+
|
5
|
+
# Pixel Ratio Srcsets
|
6
|
+
|
7
|
+
A Pixel Ratio srcset looks like this:
|
8
|
+
|
9
|
+
```html
|
10
|
+
srcset="myimage-200.jpg 1.0x, myimage-300.jpg 1.5x, myimage-400.jpg 2.0x"
|
11
|
+
```
|
12
|
+
|
13
|
+
To use one, set `pixel_ratios` and `base_width`. They are most appropriate for
|
14
|
+
thumbnails and icons, where the image will be the same size on all screens, and
|
15
|
+
all you need to account for is pixel ratio.
|
16
|
+
|
17
|
+
## Base Width
|
18
|
+
|
19
|
+
_Format:_ `base_width: integer`
|
20
|
+
|
21
|
+
_Example:_ `base_width: 100`
|
22
|
+
|
23
|
+
Sets how wide the 1x image should be. Required when using a Pixel Ratio srcset.
|
24
|
+
|
25
|
+
## Pixel Ratios
|
26
|
+
|
27
|
+
_Format:_ `pixel_ratios: [number, number, number (...)]`
|
28
|
+
|
29
|
+
_Example:_ `pixel_ratios: [1, 1.5, 2]`
|
30
|
+
|
31
|
+
Array of images to construct, given in multiples of the base width.
|
32
|
+
|
Binary file
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
sort: 8
|
3
|
+
---
|
4
|
+
|
5
|
+
# Width & Height (Anti-Loading-Jank)
|
6
|
+
|
7
|
+
_Format:_
|
8
|
+
|
9
|
+
```yml
|
10
|
+
dimension_attributes: true | false
|
11
|
+
```
|
12
|
+
|
13
|
+
_Example:_
|
14
|
+
|
15
|
+
```yml
|
16
|
+
dimension_attributes: true
|
17
|
+
```
|
18
|
+
|
19
|
+
_Default:_ `false`
|
20
|
+
|
21
|
+
Prevent page reflow (aka jank) while images are loading, by adding `width` and
|
22
|
+
`height` attributes to the `<img>` tag in the correct aspect ratio.
|
23
|
+
|
24
|
+
For an explanation of why and how you want to do this,
|
25
|
+
[here](https://youtu.be/4-d_SoCHeWE) is a great explanation.
|
26
|
+
|
27
|
+
Caveats:
|
28
|
+
* You need either `width: auto;` or `height: auto;` set in CSS on the `<img>`
|
29
|
+
tags, or they will be stretched.
|
30
|
+
* This works on `<img>` tags and `<picture>` tags when offering images in
|
31
|
+
multiple widths and formats, but it does not work if you are using art
|
32
|
+
direction (in other words, if you have multiple source images). This is
|
33
|
+
because these attributes can only be applied to the `<img>` tag, of which
|
34
|
+
there is exactly one.
|
@@ -0,0 +1,123 @@
|
|
1
|
+
---
|
2
|
+
sort: 5
|
3
|
+
---
|
4
|
+
|
5
|
+
# Width Based Srcsets
|
6
|
+
|
7
|
+
A width based srcset looks like this:
|
8
|
+
|
9
|
+
```html
|
10
|
+
srcset="myimage-800.jpg 800w, myimage-1200.jpg 1200w, myimage-2000.jpg 2000w"
|
11
|
+
```
|
12
|
+
|
13
|
+
You should use it when the size of an image depends on the size of the screen used to show it, which
|
14
|
+
generally means anything bigger than about 300 pixels. It's the default; to use it specify a
|
15
|
+
`widths` setting (or don't, for the default set), and optionally the `sizes` and `size` settings.
|
16
|
+
|
17
|
+
## A word on sizes
|
18
|
+
|
19
|
+
The `sizes` attribute is both important, and impossible to offer good defaults for. Web browsers parse
|
20
|
+
web pages line-by-line. When they run into an external asset (such as an image) they must download,
|
21
|
+
they start that process immediately without waiting to draw the page. This means that at the point
|
22
|
+
in time when the browser must decide which image to download, it has no clue how large that image
|
23
|
+
will be on the page. The sizes attribute is how we tell it.
|
24
|
+
|
25
|
+
It doesn't have to be pixel-perfect, just close enough for the browser to make a good choice. You
|
26
|
+
can't use % (percentage width of the parent container) for the same reason we have to do this at
|
27
|
+
all. If you do not provide it, the web browser will assume the image is 100vw (100% the width of
|
28
|
+
the viewport.)
|
29
|
+
|
30
|
+
## How to create a sizes attribute
|
31
|
+
|
32
|
+
First, Load the page and image as they will appear in the final site. (Basically write the rest of
|
33
|
+
the preset.)
|
34
|
+
|
35
|
+
Next, using either dev tools or by manipulating the browser window itself, determine how large the
|
36
|
+
image will be for all reasonable screen sizes. Organize this information into CSS measurements
|
37
|
+
(using `vw`, `vh`, `px`, `em`, or a calculation based on those units) associated with your
|
38
|
+
named CSS media queries, and enter them into the relevant preset. **Order matters**; enter these
|
39
|
+
from most to least restrictive. The browser will ignore everything after the first media query it
|
40
|
+
finds that is true.
|
41
|
+
|
42
|
+
**Example:** on my particular site, for screens 900px or smaller, inline images are the width of the
|
43
|
+
viewport minus 9px of padding on either side. For screens 901px or larger, they are a constant 862px
|
44
|
+
wide. The relevant lines in my config file look like this:
|
45
|
+
|
46
|
+
```yml
|
47
|
+
media_queries:
|
48
|
+
full_width: 'min-width: 901px'
|
49
|
+
# (...)
|
50
|
+
|
51
|
+
presets:
|
52
|
+
default:
|
53
|
+
# (...)
|
54
|
+
sizes:
|
55
|
+
full_width: 862px
|
56
|
+
size: calc(100vw - 18px)
|
57
|
+
```
|
58
|
+
|
59
|
+
## Settings Reference
|
60
|
+
|
61
|
+
### Widths
|
62
|
+
|
63
|
+
_Format:_ `widths: [integer, integer, (...)]`
|
64
|
+
|
65
|
+
_Example:_ `widths: [600, 800, 1200]`
|
66
|
+
|
67
|
+
_Default_: `[400, 600, 800, 1000]`
|
68
|
+
|
69
|
+
Array of image widths to generate, in pixels.
|
70
|
+
|
71
|
+
### Media Widths
|
72
|
+
|
73
|
+
_Format:_
|
74
|
+
|
75
|
+
```yml
|
76
|
+
media_widths:
|
77
|
+
(media_query name): [integer, integer, (...)]
|
78
|
+
```
|
79
|
+
|
80
|
+
_Example:_
|
81
|
+
|
82
|
+
```yml
|
83
|
+
media_widths:
|
84
|
+
mobile: [400, 600, 800]
|
85
|
+
```
|
86
|
+
|
87
|
+
_Default:_ `widths` setting
|
88
|
+
|
89
|
+
If you are using art direction, there is no sense in generating desktop-size files for your mobile
|
90
|
+
image. Similarly, there's no sense in generating 300px wide versions of your ultrawide crop. You can
|
91
|
+
specify sets of widths to associate with given media queries.
|
92
|
+
|
93
|
+
### Sizes
|
94
|
+
|
95
|
+
_Format:_
|
96
|
+
|
97
|
+
```yml
|
98
|
+
sizes:
|
99
|
+
(media preset): (CSS dimension)
|
100
|
+
(...)
|
101
|
+
```
|
102
|
+
|
103
|
+
_Example:_
|
104
|
+
|
105
|
+
```yml
|
106
|
+
sizes:
|
107
|
+
mobile: 80vw
|
108
|
+
tablet: 60vw
|
109
|
+
desktop: 900px
|
110
|
+
```
|
111
|
+
|
112
|
+
Conditional sizes, used to construct the `sizes=` HTML attribute telling the browser how wide your
|
113
|
+
image will be (on the screen) when a given media query is true. CSS dimensions can be given in `px`,
|
114
|
+
`em`, or `vw`. Provide these in order of most restrictive to least restrictive. The browser will
|
115
|
+
choose the first one with an applicable media query.
|
116
|
+
|
117
|
+
### Size
|
118
|
+
|
119
|
+
_Format:_ `size: (CSS Dimension)`
|
120
|
+
|
121
|
+
_Example:_ `size: 80vw`
|
122
|
+
|
123
|
+
Unconditional `sizes` setting, to be supplied either alone or after all conditional sizes.
|
@@ -0,0 +1,65 @@
|
|
1
|
+
---
|
2
|
+
sort: 1
|
3
|
+
---
|
4
|
+
|
5
|
+
# How to write a preset
|
6
|
+
|
7
|
+
## 0. Pick a name
|
8
|
+
|
9
|
+
* Preset names should be a single word, and they can't contain periods.
|
10
|
+
* `default` is used when you don't specify one in a liquid tag.
|
11
|
+
* Anything beginning with `jpt-` is off limits.
|
12
|
+
|
13
|
+
## 1. Pick a Markup Format
|
14
|
+
|
15
|
+
The high level, overall markup format is controlled with the `markup:` setting, documented
|
16
|
+
[here](markup_formats). You probably want the default setting of `auto`, unless you're doing some
|
17
|
+
form of post-processing.
|
18
|
+
|
19
|
+
If you have a lot of images below-the-fold, consider setting up lazy-loading with an appropriate
|
20
|
+
javascript library (there are tons) and `data_auto`.
|
21
|
+
|
22
|
+
## 2. Choose a srcset format.
|
23
|
+
|
24
|
+
For images that are different sizes on different screens (most images), use a [width-based
|
25
|
+
srcset](width_srcsets) (which is the default). When using this format, it's important to create a
|
26
|
+
sizes attribute, documented at the link above.
|
27
|
+
|
28
|
+
Use a [pixel-ratio srcset](pixel_ratio_srcsets) when the image will always be the same size,
|
29
|
+
regardless of screen width (thumbnails, avatars, icons, etc).
|
30
|
+
|
31
|
+
## 3. Choose a set of image widths.
|
32
|
+
|
33
|
+
For width-based srcsets, set `widths:`. For pixel-ratio srcsets, set `base_width:` and
|
34
|
+
`pixel_ratios:`. You want 3-6 sizes that cover a wide range of devices.
|
35
|
+
|
36
|
+
## 4. Choose a set of image formats.
|
37
|
+
|
38
|
+
Accomplish this by setting `formats: [format1, format2, etc...]`
|
39
|
+
|
40
|
+
* `webp` has [broad support](https://caniuse.com/?search=webp) and is an obvious choice.
|
41
|
+
* `avif` has [bad](https://caniuse.com/?search=avif) (but improving) support, and for some reason is slow to generate, but gets better
|
42
|
+
file sizes than webp.
|
43
|
+
* `jp2` is [Apple's baby](https://caniuse.com/?search=jp2).
|
44
|
+
* `original` spits out whatever you put in.
|
45
|
+
|
46
|
+
Order matters; browsers will use the first one they support.
|
47
|
+
|
48
|
+
* `[webp, original]` is a good compromise of build resources, support, and performance.
|
49
|
+
* `[webp, jp2, original]` brings Safari users along for the ride.
|
50
|
+
* `[avif, original]` If you don't care about browsers that aren't chrome, or build time.
|
51
|
+
* `[avif, webp, jp2, original]` might be overkill, but it keeps everyone happy.
|
52
|
+
|
53
|
+
## 5. Consider enabling dimension attributes.
|
54
|
+
|
55
|
+
This step prevents page reflow on image load (especially when lazy loading), but requires some prep.
|
56
|
+
|
57
|
+
1. Make sure your CSS is correct. You need something like `width: 100%` and `height: auto` (which
|
58
|
+
is why they aren't turned on by default.) Without this step, you'll get crazy sizes and/or
|
59
|
+
stretched images.
|
60
|
+
2. Set `dimension_attributes: true`
|
61
|
+
|
62
|
+
## 6. Make any other necessary changes.
|
63
|
+
|
64
|
+
Look through the options in the sidebar to the left, adjust as required. Note that the `data_*`
|
65
|
+
output formats have a few special options, documented on their respective pages.
|