Skip to content

Instantly share code, notes, and snippets.

@jasperf
Last active October 27, 2023 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasperf/6a3e59b949780edd3532ca48db4b3fe6 to your computer and use it in GitHub Desktop.
Save jasperf/6a3e59b949780edd3532ca48db4b3fe6 to your computer and use it in GitHub Desktop.
Elementor Slider Pro with Swiper Slider issues using background images using CSS instead of HTML

See Swiper Slider Lazy Loading example. The Elementor Slider Widget Pro uses Swiper and basic setup uses background images with CSS [link]. They do not use HTML tags like <div> or <img> with src, data-src or srcset . To use lazy loading HTML markup has to be changed as shown in example.

With this HTML markup that we could also use Imagify to load webP images when possible using swapping with JavaScript. Unfortunately this is not possible with the current setup of Elementor Slider Pro.

@jasperf
Copy link
Author

jasperf commented Oct 27, 2023

Can be done server side on Nginx using

location ~* ^(/.+)\.(jpg|jpeg|jpe|png|gif)$ {
  add_header Vary Accept;

  if ($http_accept ~* "webp"){
    set $imwebp A;
  }
  if (-f $request_filename.webp) {
    set $imwebp  "${imwebp}B";
  }
  if ($imwebp = AB) {
    rewrite ^(.*) $1.webp;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment