symfony/ux-lazy-image
Symfony UX LazyImage makes lazy-loading images simple in Symfony apps. It offers a Twig component for native browser lazy loading, optional placeholders, and performance-friendly rendering that defers offscreen images, reduces initial page weight, and helps improve Core Web Vitals.
Architecture fit — poor as a package, good as a reference
symfony/ux-lazy-image is a Symfony UX bundle. The PHP surface is glue: a bundle class registered on the Symfony kernel, a Stimulus controller registered through symfony/stimulus-bundle, and a Twig extension/tag exposing the component. A Laravel app has no kernel bundle registration, no Twig, and no AssetMapper/Webpack Encore pipeline — essentially none of the PHP code transfers.data-controller attribute contract. That layer is framework-agnostic and portable to Alpine.js or vanilla JS with modest effort.Integration feasibility — moderate, JS-only path
data-lazy-src initializer, register it in resources/js/app.js under Vite, and mirror the Twig API with a Blade <x-lazy-image> component.Technical risk — low code risk, high relevance risk
loading="lazy" plus fetchpriority already delivers most of the benefit for free. The package's differentiator is placeholder transitions and a polyfill-free controller — a meaningful but narrow win, concentrated on hero/above-fold imagery.Key questions to resolve before commitment
loading="lazy" on our actual templates? This is the go/no-go gate.Stack fit
loading="lazy" for the long tail of images, (b) package-derived controller for hero and above-fold images where placeholder transitions measurably help.Migration path
x-lazy-image) or vanilla initializer; register in resources/js/app.js; replace data-controller attributes with our own contract.<x-lazy-image> mirroring the Twig API surface (src, srcset, sizes, placeholder, alt, class passthrough) so template authors see one interface.intervention/image + a PHP blurhash encoder; persist the hash on the media model; expose it to the component.Compatibility
Sequencing
Maintenance
Support
Scaling
srcset/sizes becomes performance-critical once we are optimizing at this granularity. Validate generated URLs resolve to cacheable, versioned assets.Failure modes
loading="lazy", which fails open. Mitigate with <noscript> eager fallbacks and, where feasible, a real src attribute.style-src; use nonces or utility classes.Ramp-up
Recommendation: do not add the Composer package. Mine it for the controller pattern and the placeholder contract; vendor the JS, ship a Blade component, and approve a one-week spike gated on measured LCP improvement over native lazy loading.
How can I help you explore Laravel packages today?