Understand the Responsive Images technique
mainThe Laravel MediaLibrary uses a responsive images technique to optimize loading. It works by:
- Rendering an
<img>tag with multiplesrcsetvalues. - Using an initial
sizes="1px"attribute to render an inline base64-encoded SVG placeholder first. - Using JavaScript to update the
sizesattribute to the actual width of the image in the layout once the page has loaded. - Using a
vw(viewport width) value for the updated width, which allows the browser to load larger image versions automatically when the browser window is upscaled.
To see this in action, you can throttle your network in Chrome and disable the cache, or resize your browser window to trigger different image loads.