Add lazy load to background images
See original GitHub issueHi all,
Love Slick, thanks for creating this! Was wondering if the lazy load logic could also be added to background images that may be attached to each slide. Right now I’m using background-size:cover
on desktop (and manually setting the height) compared to swapping the background out for a static image on smaller devices. I could obviously add the lazy load handler for the inline images, but they’d be loaded regardless because of the background image reference. Thanks!
Issue Analytics
- State:
- Created 9 years ago
- Reactions:7
- Comments:28 (2 by maintainers)
Top Results From Across the Web
Lazy loading images - web.dev
Chrome and Firefox both support lazy loading with the loading attribute. This attribute can be added to <img> elements, and also to <iframe> ......
Read more >Lazy Loading Images – The Complete Guide - ImageKit.io
Images on a webpage can be loaded in two ways - using the <img> tag, or using the CSS `background` property. Let's first...
Read more >How to Lazy Load div background images - Stack Overflow
First you need to think off when you want to swap. For example you could switch everytime when its a div tag thats...
Read more >Lazy loading CSS background images for better website ...
Find out how to lazy load CSS background images to improve your website loading performance.
Read more >How to Lazyload Background Images in WordPress - MainWP
Another plugin option for lazyloading of background images is to use the Lazy Loader plugin. ... If you are using the WP Rocket...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I use the lazyLoaded Event and replace the src attribute with the background attribute. Looks something like this:
Maybe this helps! This way you build your slides normally with tags and data-lazy attributes, but have the benefits of the fixed height/cover etc. props. Also fading on of the slick slider works properly.
I often have slides generated from a database (images + etc are set in CMS) and are therefore not available to CSS. And having inline images act like background-size:cover takes some js trickery and is a real pain. This would be of great help to me.