backdrop / backdrop-issues

Issue tracker for Backdrop core.
144 stars 39 forks source link

In Lazy loading settings, replace Automatic with Default #6428

Open yorkshire-pudding opened 6 months ago

yorkshire-pudding commented 6 months ago

While I was adding the lazy loading settings to the srcset Image module, I was copying what Core had done until @laryn pointed out that actually auto is no longer relevant for any browser.

Source: https://web.dev/articles/browser-level-image-lazy-loading

Previously, Chromium automatically lazy-loaded any images that were well suited to being deferred if Lite mode was enabled on Chrome for Android and the loading attribute was either not provided or set as loading="auto". However, Lite mode has been deprecated (as was the non-standard loading="auto") and there are currently no plans to provide automatically lazy-load of images in Chrome.

Backdrop currently looks like this:

image

In srcset Image, as this is a new feature, I've implemented like this, but I'm happy to adapt to whatever is decided for core to have consistency in language.

image

The three relevant parts of the backdrop code are:

https://github.com/backdrop/backdrop/blob/266a5018c5e675ee88e51dd6e732da3ec464a696/core/modules/image/image.field.inc#L767-L774

    if (!empty($display['settings']['image_load'])) {
      // Although available in Chromium, the 'auto' value is not mentioned in
      // the specification. Since it may be subject to change, we recommend not
      // to use it until it gets officially included.
      if ($display['settings']['image_load'] != 'auto') {
        $item['attributes']['loading'] = $display['settings']['image_load'];
      }
    }

https://github.com/backdrop/backdrop/blob/266a5018c5e675ee88e51dd6e732da3ec464a696/core/modules/image/image.field.inc#L740-L742

  if (!empty($settings['image_load']) && $settings['image_load'] != 'auto') {
    $summary[] = t('Loading: @speed', array('@speed' => $settings['image_load']));
  }

https://github.com/backdrop/backdrop/blob/266a5018c5e675ee88e51dd6e732da3ec464a696/core/modules/image/image.field.inc#L688-L700

  $element['image_load'] = array(
    '#title' => t('Image loading'),
    '#type' => 'radios',
    '#default_value' => $settings['image_load'],
    '#options' => array(
      'lazy' => t('Lazy'),
      'auto' => t('Automatic'),
      'eager' => t('Eager'),
    ),
  );
  $element['image_load']['lazy']['#description'] = t('Defer loading offscreen images until viewers scroll nearby. "Nearby" is determined by each browser.');
  $element['image_load']['auto']['#description'] = t('Each browser will determine whether or not to lazily load the image.');
  $element['image_load']['eager']['#description'] = t('Load this image immediately, regardless of where it is located on the page.');
yorkshire-pudding commented 6 months ago

Wasn't getting any interest with previous title, so thought being a bit more opinionated would get someone to disagree and suggest something else, or enable people to agree on this.

laryn commented 6 months ago

@yorkshire-pudding Do you know how D10 handles this?

yorkshire-pudding commented 6 months ago

@laryn - I haven't used D10 so no idea.

yorkshire-pudding commented 2 weeks ago

@laryn - I have access to one, so here is a screenshot: image

It doesn't give the option of letting the browser decide, just lazy or eager