Do This to Improve Image Loading on Your Website
Publikováno: 20.2.2020
Jen Simmons explains how to improve image loading by simply using width and height attributes. The issue is that there’s a lot of jank when an image is first loaded because an img
will naturally have a height of 0
before the image asset has been successfully downloaded by the browser. Then it needs to repaint the page after that which pushes all the content around. I’ve definitely seen this problem a lot on big news websites.
Anyway, Jen is … Read article
The post Do This to Improve Image Loading on Your Website appeared first on CSS-Tricks.
Jen Simmons explains how to improve image loading by simply using width and height attributes. The issue is that there’s a lot of jank when an image is first loaded because an img
will naturally have a height of 0
before the image asset has been successfully downloaded by the browser. Then it needs to repaint the page after that which pushes all the content around. I’ve definitely seen this problem a lot on big news websites.
Anyway, Jen is recommending that we should add height
and width
attributes to images like so:
<img src="dog.png" height="400" width="1000" alt="A cool dog" />
This is because Firefox will now take those values into consideration and remove all the jank before the image has loaded. That means content will always stay in the same position, even if the image hasn’t loaded yet. In the past, I’ve worked on a bunch of projects where I’ve placed images lower down the page simply because I want to prevent this sort of jank. I reckon this fixes that problem quite nicely.
Direct Link to Article — Permalink
The post Do This to Improve Image Loading on Your Website appeared first on CSS-Tricks.