|
1 | 1 | [[uploadcare-srcset-steps]] |
2 | 2 | == `uploadcare_srcset_steps` |
3 | 3 |
|
4 | | -Defines an array of numeric values representing the widths for responsive images. These widths are used to generate the `srcset` attribute for images, allowing browsers to select the most appropriate resolution based on the device's display and network conditions. |
| 4 | +Specifies an array of numeric values representing the widths used to generate the `srcset` attribute for responsive images. This enables browsers to select the most suitable resolution based on the device’s display and network conditions. |
5 | 5 |
|
6 | | -Customize this array to include only the widths you need for your application. For example, you can reduce the number of resolutions for faster processing or add specific sizes required for your layout. |
| 6 | +Customize this array to include **only** the widths required for your application. Reducing the number of resolutions can improve processing speed, while adding specific sizes can accommodate unique layout needs. |
7 | 7 |
|
8 | 8 | *Type:* `+Array+` |
9 | 9 |
|
10 | 10 | *Default:* `+[100, 200, 300, 500, 750, 1000, 1250, 1500, 2000, 2500, 3000]+` |
11 | 11 |
|
| 12 | +=== Example: Generated `srcset` Attribute with Custom Widths |
| 13 | + |
| 14 | +When an image is uploaded, its original width is used to create a `srcset` attribute with downscaled images for the defined widths. For instance, if the image width is 780 pixels and `uploadcare_srcset_steps` is set to `[100, 200, 300, 500, 750]`, the resulting `srcset` will look like this: |
| 15 | + |
| 16 | +.Example: Responsive 780px Image with Custom Widths in `srcset` |
| 17 | +[source,html] |
| 18 | +---- |
| 19 | +<img |
| 20 | + style="width: min(780px, 100%); aspect-ratio: 780 / 780;" |
| 21 | + src="https://ucarecdn.com/de937e77-2fec-4781-91c1-55dae67803cd/-/preview/" |
| 22 | + sizes="(min-width: 780px) 780px, 100vw" |
| 23 | + srcset=" |
| 24 | + https://ucarecdn.com/de937e77-2fec-4781-91c1-55dae67803cd/-/resize/100x/ 100w, |
| 25 | + https://ucarecdn.com/de937e77-2fec-4781-91c1-55dae67803cd/-/resize/200x/ 200w, |
| 26 | + https://ucarecdn.com/de937e77-2fec-4781-91c1-55dae67803cd/-/resize/300x/ 300w, |
| 27 | + https://ucarecdn.com/de937e77-2fec-4781-91c1-55dae67803cd/-/resize/500x/ 500w, |
| 28 | + https://ucarecdn.com/de937e77-2fec-4781-91c1-55dae67803cd/-/resize/750x/ 750w, |
| 29 | + https://ucarecdn.com/de937e77-2fec-4781-91c1-55dae67803cd/-/preview/ 780w |
| 30 | + "> |
| 31 | +---- |
| 32 | + |
| 33 | +This ensures the browser selects the optimal image size based on the viewport and device characteristics, enhancing performance and user experience. On devices with narrower viewports, smaller images (e.g., 100w or 200w) will be prioritized, reducing bandwidth usage. |
| 34 | + |
12 | 35 | === Example: Customizing `uploadcare_srcset_steps` |
13 | 36 |
|
| 37 | +To customize the array, update the configuration as shown below: |
| 38 | + |
14 | 39 | [source,js] |
15 | 40 | ---- |
16 | 41 | tinymce.init({ |
17 | 42 | selector: 'textarea', |
18 | 43 | plugins: 'uploadcare', |
19 | 44 | toolbar: 'uploadcare', |
20 | 45 | uploadcare_public_key: '<your-public-key>', |
21 | | - uploadcare_srcset_steps: [100, 200, 300, 500], |
| 46 | + uploadcare_srcset_steps: [100, 200, 300, 500, 750], |
22 | 47 | }); |
23 | | ----- |
| 48 | +---- |
0 commit comments