Skip to content

FigureGlide JS ​

Use the FigureGlide component to display responsive images with a League Glide server.

Usage ​

Register the component in your JavaScript app and use it in your templates. The component sets the w and h parameters of the data-src URL to the size of the <img> DOM element, multiplied by the device pixel ratio. It keeps the other parameters of the URL.

A component mounts on its configured name, and the markup below writes data-component="Figure", so declare that name on a subclass:

js
import { registerComponent } from '@studiometa/js-toolkit';
import { FigureGlide } from '@studiometa/ui';

class Figure extends FigureGlide {
  static config = {
    name: 'Figure',
  };
}

registerComponent(Figure);
html
<div class="card">
  <figure data-component="Figure" data-option-fit="crop" data-option-fm="webp">
    <img
      data-ref="img"
      src="placeholder.png"
      data-src="/img/photo.jpg?w=400&h=400"
      width="400"
      height="400"
      alt="" />
  </figure>
</div>

Size grid ​

Each dimension is rounded up to a multiple of the step option, after the multiplication by the device pixel ratio. A dimension larger than the maxSize option scales the two dimensions down with the ratio of the image, and the result is rounded to the grid again, but not above maxSize. Thus the component only requests a limited set of sizes, which the server can cache.

With the default options, an image shown at 320×380 pixels on a screen with a device pixel ratio of 2 requests w=700&h=800.

Signed URLs

A signed URL is not valid when its w and h parameters change. Configure the server to accept unsigned URLs for the sizes of the grid, or set the disable option to keep the URL of the template.