Skip to content

LSCWP image optimization: WebP conversion, lazy load, and AVIF

Configure LSCWP to convert images to WebP or AVIF, enable lazy loading, and serve the right format per browser — without breaking the media library.

Images are typically the single largest contributor to page weight, and serving them in the wrong format or without lazy loading means downloading bytes the user never sees. LSCWP converts JPEG and PNG uploads to WebP (and optionally AVIF) on the server and serves the converted format only to browsers that declare support, falling back to the original for those that do not. This article covers the full configuration path — format conversion, lazy load setup, AVIF opt-in, and the troubleshooting steps when converted images do not appear.

How to verify

Check whether image optimization is active and what formats are being served:

# Confirm the server can convert images (ImageMagick or GD required)
php -r "echo extension_loaded('imagick') ? 'ImageMagick OK' : 'no ImageMagick'; echo PHP_EOL;"
php -r "echo function_exists('imagecreatefrompng') ? 'GD OK' : 'no GD'; echo PHP_EOL;"

# Check current LSCWP image optimization state
wp option get litespeed.conf.img_optm-auto
wp option get litespeed.conf.img_optm-webp

# Request an image and see what format is served
curl -sI -H "Accept: image/webp" https://example.com/wp-content/uploads/photo.jpg \
  | grep -i content-type
# Expect: image/webp

curl -sI https://example.com/wp-content/uploads/photo.jpg \
  | grep -i content-type
# Expect: image/jpeg (fallback for non-WebP browsers)

What’s happening

LSCWP image optimization operates in two layers. The first is server-side conversion: when you run an optimization job (manually or via the auto-optimization cron), the plugin calls ls.quic.cloud with each original image, receives a WebP or AVIF-encoded version in return, and stores it alongside the original in wp-content/uploads/ with a .webp or .avif extension.

The second layer is delivery. LSCWP hooks into WordPress image output — <img> tags and srcset attributes — and rewrites them to point at the converted file. The rewrite only happens if the browser sends Accept: image/webp (or image/avif) in the request header. For browsers that do not, the original file URL is used. This means no .htaccess rewrite rules and no CDN configuration is required for basic operation — the format selection happens in PHP before the HTML is cached.

On-server vs cloud optimization. LSCWP can call ls.quic.cloud to perform the conversion (the cloud path), or it can use local PHP image libraries (GD or ImageMagick) when the local optimization option is enabled. Local conversion is faster for large libraries (no API round-trip) but produces slightly larger files than the cloud encoder. For most managed environments, the cloud path is acceptable during business hours; local conversion is better for overnight batch jobs.

The procedure

Step 1 — Request an API key and enable image optimization.

Image optimization requires a valid domain API key (LiteSpeed Cache → General → Domain Key). Without it, the cloud conversion endpoint is not available.

Go to LiteSpeed Cache → Image Optimization:

  • Auto Request Cron — On (runs the optimization job on a schedule)
  • Auto Pull Cron — On (fetches completed results from the cloud)
  • Optimize Original Images — Off unless you want originals replaced (not recommended; keep originals for re-optimization with better encoders)
  • WebP — On

Step 2 — Run the first optimization pass.

Click “Send Optimization Requests” to queue all existing images. This sends each image to ls.quic.cloud. For sites with large media libraries (>1,000 images), this may take several hours. Check progress:

# Via WP-CLI LSCWP commands
wp litespeed-img status
wp litespeed-img pull

Alternatively from the dashboard: LiteSpeed Cache → Image Optimization → Image Optimization Summary shows pending, processing, and completed counts.

Step 3 — Enable WebP delivery.

Go to LiteSpeed Cache → Image Optimization → WebP:

  • WebP Replacement — On
  • WebP Attribute — This controls whether LSCWP rewrites src and srcset attributes directly. Leave On for standard delivery.

Step 4 — Enable AVIF (optional).

AVIF provides significantly better compression than WebP (typically 30-50% smaller) but is supported by fewer browsers (Chrome 85+, Firefox 93+, Safari 16+). If your audience is primarily modern-browser users:

  • AVIF — On (in Image Optimization settings)

LSCWP will request both WebP and AVIF conversions. The plugin delivers AVIF to browsers that declare Accept: image/avif and WebP to those that only declare Accept: image/webp. Older browsers receive the original.

Note: AVIF encoding is significantly slower than WebP, so the cloud queue time for AVIF jobs is longer.

Step 5 — Enable lazy loading.

Go to LiteSpeed Cache → Page Optimization → Media Settings:

  • Lazy Load Images — On
  • Lazy Load Iframes — On (optional; defers embedded YouTube, Vimeo, and maps)
  • Add Missing Image Dimensions — On (prevents Cumulative Layout Shift by ensuring width/height attributes are present)

Step 6 — Exclude above-the-fold images from lazy load.

The hero image and logo should not be lazy loaded — they are visible on page load and lazy loading them actually worsens LCP. Add exclusions in Lazy Load Exclude:

.hero-image
.site-logo
img#logo

Or use the WordPress fetchpriority="high" attribute on the hero image and add it to the lazy load exclusion list.

Step 7 — Test format delivery across browsers.

In Chrome DevTools, go to Network → Images and inspect the Content-Type column. WebP images should show image/webp. In Safari (which supports WebP from version 14 but not AVIF until 16), originals should be served.

Use curl to simulate a non-WebP browser:

curl -sI https://example.com/wp-content/uploads/photo.jpg \
  -H "Accept: text/html,application/xhtml+xml" \
  | grep content-type
# Expect: image/jpeg

Common pitfalls

WebP images not appearing despite optimization complete. The .htaccess rewrite rule for WebP fallback is missing or incorrect. Check wp-content/uploads/.htaccess for LSCWP’s WebP rules:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{REQUEST_FILENAME}.webp -f
RewriteRule ^(.+)\.(jpe?g|png)$ $1.webp [T=image/webp,E=accept:1]
</IfModule>

If the file is missing, navigate to LiteSpeed Cache → Toolbox and click “Generate WebP .htaccess.”

Optimization jobs stuck in “Processing.” The cloud queue is backed up or the API key has hit a quota limit. Check usage at ls.quic.cloud → Image Optimization. Free accounts have monthly limits.

Images appear broken after optimization. The WebP conversion produced a corrupt file. Use WP-CLI to re-request optimization for the specific image:

wp litespeed-img mark --status=notsubmit --id=123
wp litespeed-img pull

Lazy loaded images cause CLS. The width and height attributes are missing from <img> tags. Enable “Add Missing Image Dimensions” in Media Settings or ensure your theme passes dimensions to wp_get_attachment_image.

AVIF not served even for Chrome. The Accept header from the browser includes image/avif but the file does not exist yet — AVIF generation is queued but not complete. Check wp litespeed-img status and wait for the pull job to finish.


Image optimization is one of the fastest wins on most WordPress sites — the work is done once and the savings compound across every page load. Stack Harbor configures LSCWP image optimization, schedules optimization jobs, and validates format delivery as part of managed operations.