Skip to content

Commit ca38838

Browse files
committed
update responsive image settings
1 parent 3b4052a commit ca38838

File tree

1 file changed

+97
-48
lines changed

1 file changed

+97
-48
lines changed

docs/classic-ui/images.md

Lines changed: 97 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -261,74 +261,123 @@ A `srcset` can help the browser serve the best fitting image for the current use
261261
Which image scale is best for the user can be decided on different metrics.
262262

263263

264-
### viewport size
264+
### default configuration
265265

266-
The first is metric would be the viewport size.
266+
The default configuration covers image size optimization and will provide the Browser with the needed information to load the optimal image.
267267

268268
```json
269269
{
270-
"scale": "large",
271-
"media": "(max-width:800px)"
272-
},
273-
{
274-
"scale": "larger"
270+
"large": {
271+
"title": "Large",
272+
"sourceset": [
273+
{"scale": "larger"},
274+
],
275+
},
276+
"medium": {
277+
"title": "Medium",
278+
"sourceset": [
279+
{"scale": "teaser"},
280+
],
281+
},
282+
"small": {
283+
"title": "Small",
284+
"sourceset": [
285+
{"scale": "preview"},
286+
],
287+
},
275288
}
276289
```
277290

278-
With this definition the browser will use the `large` scale when the viewport's width is 800 pixels or fewer.
279-
When the viewport width is greater than 800 pixels, the browser will use the larger scale `1000px`.
280-
291+
### optional settings
281292

282-
### Pixel density
293+
By default for every srcset all available scales will be included. That mean
283294

284-
Another metric is the pixel density of the user's screen.
285-
This metric denotes the pixel density, or resolution, of an output device in {term}`dots per inch` (DPI).
295+
To exclude some scales completely from the srcset definition, one can use `excludeScales`:
286296

287297
```json
288298
{
289-
"scale": "huge",
290-
"media": "(min-resolution: 192dpi), (-webkit-min-device-pixel-ratio: 2)"
291-
},
292-
{
293-
"scale": "large"
299+
"excludedScales": ["tile", "icon", "listing"],
300+
"large": {
301+
"title": "Large",
302+
"sourceset": [
303+
{"scale": "larger"},
304+
],
305+
},
294306
}
295307
```
296308

297-
With this definition the browser will use the `huge` scale of 1600 pixels when the screen has a density of 192 DPI, also knows as `2x`.
298-
We use here two different media queries to also support older Safari versions.
299-
Mobile devices with Safari-like iPhones only support the old non-standard media query.
300-
If you do not care about IE support, you can use `min-resolution: 2dppx`, which is closer to `2x`.
301-
The most common variants are:
302-
303-
- `1x`: 96 DPI
304-
- `1.25x`: 120 DPI
305-
- `1.5x`: 144 DPI
306-
- `2x`: 192 DPI
307-
- `3x`: 288 DPI
309+
to restrict the list of used scales inside of a srcset, one can set the `additionalScales` parameter with an array of allowed scales.
310+
Without this parameter all scales which are not globally excluded scales will be used.
308311

312+
```json
313+
"small": {
314+
"title": "Small",
315+
"sourceset": [
316+
{
317+
"scale": "preview",
318+
"additionalScales": ["large", "larger", "great", "huge"],
319+
},
320+
],
321+
},
322+
```
309323

310-
### Combining viewport size and pixel density
324+
This means the generated srcset will contain the scales from preview up to huge, but not mini for example.
325+
Another benefit here is that we can define two different source tags with different scales for [art direction](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images#art_direction).
326+
This means will force the Browser to deliver a different image for smaller screens.
311327

312-
It is also possible to combine the two metrics.
328+
Let's have a look at a more advanced configuration:
313329

314330
```json
315331
{
316-
"scale": "great",
317-
"media": "(max-width:799px) and (min-resolution: 144dpi), (max-width:799px) and (-webkit-min-device-pixel-ratio: 1.5)"
318-
},
319-
{
320-
"scale": "large",
321-
"media": "(max-width:799px)"
322-
},
323-
{
324-
"scale": "huge",
325-
"media": "(min-width:800px) and (min-resolution: 144dpi), (max-width:800px) and (-webkit-min-device-pixel-ratio: 1.5)"
326-
},
327-
{
328-
"scale": "larger",
329-
"media": "(min-width:800px)"
330-
},
331-
{
332-
"scale": "huge"
332+
"excludedScales": ["tile", "icon", "listing"],
333+
"large": {
334+
"title": "Large",
335+
"sourceset": [
336+
{"scale": "larger"},
337+
],
338+
},
339+
"medium": {
340+
"title": "Medium",
341+
"sourceset": [
342+
{
343+
"scale": "teaser",
344+
"additionalScales": ["large", "larger", "great", "huge"],
345+
},
346+
{
347+
"scale": "mobile_crop",
348+
"additionalScales": ["mobile_crop_highres"],
349+
},
350+
],
351+
},
352+
"small": {
353+
"title": "Small",
354+
"sourceset": [
355+
{"scale": "preview"},
356+
],
357+
},
333358
}
359+
360+
```
361+
362+
which will result in a srcset like this, for a medium image:
363+
364+
```json
365+
<picture>
366+
<source media="(min-width:800px)"
367+
srcset="https://picsum.photos/id/1011/400 400w,
368+
https://picsum.photos/id/1011/800 800w,
369+
https://picsum.photos/id/1011/1000 1000w,
370+
https://picsum.photos/id/1011/1200 1200w,
371+
https://picsum.photos/id/1011/1600 1600w
372+
"
373+
sizes="400px">
374+
<source media="(max-width:799px)"
375+
srcset="https://picsum.photos/id/1012/800 800w,
376+
https://picsum.photos/id/1012/1000 1000w
377+
"
378+
sizes="96vw">
379+
<img src="https://picsum.photos/id/1011/400" width="400px" height="400px">
380+
</picture>
334381
```
382+
383+

0 commit comments

Comments
 (0)