All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

HTML-Only Conditional Lazy Loading Using Preload and Media Queries

By

netol

4mo ago· 2 min readen

Summary

The article discusses a technical workaround for conditional lazy loading of images in HTML without server-side device detection or JavaScript. It addresses the challenge that "above the fold" positioning varies by screen size, making it difficult to correctly apply lazy loading to images that might be above the fold on desktop but below on mobile (or vice versa). The proposed solution leverages browser behavior where images won't be delayed if already fetched, using preload with media queries to conditionally load images based on screen size.

Key quotes

· 4 pulled
The accepted practice is to not add lazy-loading to images above the fold, especially the LCP image.
The problem is that 'above the fold' depends on screen size: an image can be above the fold on desktop and below it on mobile.
With native lazy loading and static HTML (e.g., without device detection on the server side or JavaScript), you normally have to pick one behavior and get it wrong for part of your users.
But there's a small workaround that seems to work. Browsers won't delay the loading of an image if it's already been fetched.
Snippet from the RSS feed
The accepted practice is to not add lazy-loading to images above the fold, especially the LCP image. The problem is that "above the fold" depends on screen size: an image can be above the fold on desktop and below it on mobile. With native lazy loading an

You might also wanna read