Disabled JavaScript turns off native lazy loading
- Published at
- Updated at
- Reading time
- 1min
It's speedy TIL time! Did you know the loading="lazy"
attribute doesn't work when you turn off JavaScript?
Now, you do. 😉
Why doesn't lazy load work without JS? There's only one reason why we can't have nice things: of course, it's for tracking prevention.
Here's the loading
MDN documentation explaining the behavior:
Loading is only deferred when JavaScript is enabled. This is an anti-tracking measure, because if a user agent supported lazy loading when scripting is disabled, it would still be possible for a site to track a user's approximate scroll position throughout a session, by strategically placing images in a page's markup such that a server can track how many images are requested and when.
And if you really want to get into this topic, here's the related spec describing when loading="lazy"
should work.
And just to be clear, because some folks were confused: images will still load when JS is disabled. It's only the deferred loading that won't work.
Join 5.5k readers and learn something new every week with Web Weekly.