3 ms·
> Some websites require JavaScript to display images nowadays. What's wrong with <img>? Lazy loading. By default, browsers will load all images as soon as the
by atomwaffel 10y ago
> Some websites require JavaScript to display images nowadays. What's wrong with <img>?
Lazy loading. By default, browsers will load all images as soon as the page loads. If you have a long article with potentially megabytes of images, this behaviour will seriously slow down the initial load, and many readers who jump early will still download a bunch of images that they never see. That's why many sites only load images as they are about to appear, but to do that, you can't use regular <img> tags.
You're right in that JavaScript shouldn't be a requirement though. A good implementation will provide a regular <img> inside a <noscript> tag.
> Others require JavaScript to use the correct font. What's wrong with CSS?
Avoiding "flashes of invisible text"[1] when using web fonts. Unfortunately, different browsers have very different strategies for loading web fonts. Some of them will wait for the web font to load at any cost rather than showing a fallback font in the meantime. This means that you can be stuck for ages with everything in place except for the text, which is seriously irritating.
I've never implemented FOIT mitigation myself, but I assume that you could (and should) again provide a fallback in a <noscript> tag. Even without it, the text will at least still display without JavaScript, just in the second font in the font stack.
[1] https://css-tricks.com/fout-foit-foft/ https://css-tricks.com/fout-foit-foft/