The CSS scroll-behavior property may help here at some point, but its support needs to improve before it’s a viable option. It slows down the browser by forcing it to recalculate the layout of any elements that are affected by that image’s shape. Reflow is a problem because it’s a user-blocking operation. This causes reflow, where the content below or around the image gets pushed to make room for the freshly loaded image. When a user scrolls and images are lazy-loaded, those img elements go from a height of 0 pixels to whatever they need to be. Update! Times changed fast here, and to avoid lazy-load jank, all you have to do is put the correct natural width and height attributes on images and they will load nicely, even if CSS makes the image fluid with. This means that they’re not the right size in the page layout until they’re lazy-loaded. That said, it does indeed introduce a noticeable problem: images not containing the src attribute (including when it’s empty or invalid) have no height. That equals faster page loads and less data the user needs to spend. Additionally, if the user never scrolls far enough to see an image, that image is never loaded. The result is the browser loading fewer images up front so that the page loads faster. The browser requests the image and it loads into view.When the use encounters an image, JavaScript moves the data-src value into src where it belongs.JavaScript watches the user scroll down the page.GitHub has over 3,400 different lazy load repos, and those are just the ones with “lazy load” in a searchable string! Most of them rely on the same trick: Instead of putting an image’s URL in the src attribute, you put it in data-src - which is the same pattern for responsive images: There are a plethora of JavaScript-based lazy loading solutions. It prevents the browser from loading images until those images are in (or nearly in) the browser’s viewport. You know the concept of lazy loading images.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |