How To Load Images Like A Pro

Lazy Load Images Article: blog.webdevsimplified.com/202...
Images are the largest asset for most sites and the biggest cause for unresponsive, laggy sites. In this video I will show you how to use lazy loading to not only drastically speed up your applications, but to also increase the polish and quality of your site.
📚 Materials/References:
Lazy Load Images Article: blog.webdevsimplified.com/202...
Responsive Images Video: • Make Your Site Lightni...
Responsive Images Article: blog.webdevsimplified.com/202...
🌎 Find Me Here:
My Blog: blog.webdevsimplified.com
My Courses: courses.webdevsimplified.com
Patreon: / webdevsimplified
Twitter: / devsimplified
Discord: / discord
GitHub: github.com/WebDevSimplified
CodePen: codepen.io/WebDevSimplified
⏱️ Timestamps:
00:00 - Introduction
00:35 - What Is The Problem
02:17 - Lazy Loading Basics
05:15 - Advanced Blurry Loading
#LazyLoading #WDS #HTML

Пікірлер: 353

  • @snc0lt
    @snc0lt11 ай бұрын

    one of the things i like about you, is that you rarely use any framework/library for your videos and just focused on the fundamentals...! Keep it up.!

  • @TheThirdWorldCitizen

    @TheThirdWorldCitizen

    11 ай бұрын

    He does talk a lot about react tbf, but decent amount of vanilla videos.

  • @cookieman.19

    @cookieman.19

    8 ай бұрын

    He is the framework

  • @MrThebigcheese75

    @MrThebigcheese75

    6 ай бұрын

    I agree, prefer not to be bogged down with a framework, for what I do they're overkill.

  • @fatimanura6359

    @fatimanura6359

    3 ай бұрын

    yup, it helps to have more better understand, and get used to the logics

  • @rusicsemenov
    @rusicsemenov11 ай бұрын

    Hi Kail, thanks, good idea with pulse. And you can write in the keyframes 0%, 100% ... and 50%, instead repeat the same code.

  • @MrMikopi
    @MrMikopi11 ай бұрын

    I'm not that into front end side, But video making of yours is brilliant! I've even checked if I increased playback speed, but no, it was you talking at a good amount of speed, talking only about important stuff. Visual demonstrations are on point also. Thank you, good work. Edit: 11:36 that is the fastest bug fixing I've ever seen haha

  • @Diventurer
    @Diventurer11 ай бұрын

    Did not know about the loading attribute. It was very helpful for a website I develop. Thank you!

  • @SnappyScience
    @SnappyScience11 ай бұрын

    Great easy to follow vid. The blur background idea is gold.

  • @eksperiment6269
    @eksperiment626911 ай бұрын

    This is an awesome way to load images. Great video!

  • @arinqwerty
    @arinqwerty6 ай бұрын

    I love how this is detailed!!!

  • @Gio-m
    @Gio-m10 ай бұрын

    Dude you're a blessing, thank you!

  • @RobertWildling
    @RobertWildling7 ай бұрын

    Excellent video! Incredibly well explained, exceptionally well prepared! Thank you very much!

  • @leandrolepingo1783
    @leandrolepingo178310 ай бұрын

    Hi Kail, thanks, good idea with pulse.

  • @OldManBears
    @OldManBears6 ай бұрын

    You're awesome, this was incredibly helpful.

  • @user-fs6qz7be2z
    @user-fs6qz7be2z11 ай бұрын

    I was looking for EXACTLY this for my project.

  • @eliyahutarab4862
    @eliyahutarab486211 ай бұрын

    Amazing as always thank you so much man

  • @TheNewton
    @TheNewton11 ай бұрын

    8:12 in addition to online tools most image asset CDN's have parameters , or a path, to serve specific image sizes.

  • @user-uk1bx9vm4o
    @user-uk1bx9vm4o11 ай бұрын

    The process of generating and storing the blue placeholder js cumbersome - cloudinary really makes the whole thing a lot more cleaner.

  • @colindante5164
    @colindante516411 ай бұрын

    Thankyou much for sharing this awesome technique. ))))

  • @martinkarugaba
    @martinkarugaba11 ай бұрын

    Awesome tutorial, thanks Kyle.

  • @CodeCowboy64
    @CodeCowboy649 ай бұрын

    Been in web dev for 25 years, been a few since I was doing front end stuff. TIL some new to me properties, thanks!

  • @JonHaa87
    @JonHaa8711 ай бұрын

    1. I'd add an additional blur filter to the low res images, either in the browser or when generating them. Just upscaling them kinda makes them look crappy as you get lots of "square gradients" (for a lack of a better word) interpolating between the pixels instead of a nice smooth blurry version. 2. As other have said, this effect is mostly already implemented into browsers/images. If you'd save the images as progressive, they'd automatically get sharper and sharper while they load, which requires less code and doesn't even need the download of the small image versions. However you could implement an additional blur effect on top of that while they're loading for a better effect, similar to what you've done in the video. 3. The solution you've given in the video is bad as someone with scripts disabled won't see the high-res versions at all. I'd add the CSS class that hides them until they're loaded also within JS.

  • @CarlosHernandez-tg3vj
    @CarlosHernandez-tg3vj11 ай бұрын

    exactly what I needed thank you

  • @prodbybarn
    @prodbybarn11 ай бұрын

    Just what i was looking for, awesome

  • @BorisBarroso
    @BorisBarroso11 ай бұрын

    Thanks this is so useful, I have started a e-commerce site and I will use this method for the product images

  • @lamhung4899

    @lamhung4899

    11 ай бұрын

    this method is more suite for showcase , img attribute srcset is better enough for your ecom site

  • @MichaelKadzioch
    @MichaelKadzioch11 ай бұрын

    Thanks for this Video!

  • @krumbo
    @krumbo11 ай бұрын

    Great stuff thanks for sharing.

  • @derpysean1072
    @derpysean107211 ай бұрын

    This is nice. Thank you dude.

  • @iamasifimam
    @iamasifimam11 ай бұрын

    very helpfull content thankyou for sharing this.

  • @landau07
    @landau0711 ай бұрын

    Great content! Thank you!

  • @user-mi5sy1wq9v
    @user-mi5sy1wq9v11 ай бұрын

    you are such a genius!!

  • @khalidelgazzar
    @khalidelgazzar11 ай бұрын

    Grest tutorial. Thank you

  • @JoseLeMalin
    @JoseLeMalin27 күн бұрын

    Very usefull video ! Thank you !

  • @dotjs5025
    @dotjs502511 ай бұрын

    Simply amazing explanation

  • @stevensavoie856
    @stevensavoie85611 ай бұрын

    I love that the way you add lazy loading is how non-programmers think writing code is like. "If you want lazy loading, type "loading = lazy". If you want a visitor to buy things, just add a button and write "action = complete transaction with credit card or payment service.""

  • @tantalus_complex

    @tantalus_complex

    10 ай бұрын

    That's the Declarative Paradigm of programming for you. It's all about letting you describe WHAT you want (leaving the HOW to the engine). That is, you provide descriptions of what you want, piece by piece. On the other hand, what people casually mean by "programming" tends to be the Imperative Paradigm. This is all about letting you describe HOW you want things done. That is, you provide instructions, step by step.

  • @kennethbeal
    @kennethbeal11 ай бұрын

    Nice, thank you!

  • @andreaskarz
    @andreaskarz9 ай бұрын

    Super cool, thank you

  • @OrlandoVallejos
    @OrlandoVallejos9 ай бұрын

    Amazing content!

  • @minusgod
    @minusgod11 ай бұрын

    Thank you for this very informative video .. pls do make a video for video loading time will be very helpful :)

  • @ibtesumrezaaninda323
    @ibtesumrezaaninda3238 ай бұрын

    Ow man! You are awesome!

  • @kenansenagic384
    @kenansenagic3849 ай бұрын

    Great advice :)

  • @eseval
    @eseval11 ай бұрын

    Great video. Thanks.

  • @mohmarroun3189
    @mohmarroun3189Ай бұрын

    Great video!

  • @javascript_developer
    @javascript_developer11 ай бұрын

    nice tricks to load images thanks for sharing.

  • @GergelyCsermely
    @GergelyCsermely9 ай бұрын

    Thanks!

  • @krateskim4169
    @krateskim416910 ай бұрын

    That was amazing

  • @namikazedevj46
    @namikazedevj4611 ай бұрын

    what a coincidence got this issue in my job task xD thanks a lot!

  • @sunraiii
    @sunraiii11 ай бұрын

    Web development wouldn't be where it's at without KZread. Great video!

  • @calimio6

    @calimio6

    11 ай бұрын

    nah, without content creators

  • @rproctor83

    @rproctor83

    11 ай бұрын

    @@calimio6 nah, without internet

  • @merlinwarage

    @merlinwarage

    11 ай бұрын

    Did you ever hear about books? Or sites like MSDN?

  • @sunraiii

    @sunraiii

    11 ай бұрын

    ​@@merlinwarage Congrats on being a dick under a positive comment. Also, dev books are 80% fluff, 20% content and MSDN is for boomers.

  • @lukas.webdev
    @lukas.webdev11 ай бұрын

    I heard about it, but actually never used it ... But this actually seems pretty helpful. Keep it up. 😉🔥

  • @harris.sensorsoffline6419

    @harris.sensorsoffline6419

    11 ай бұрын

    Whose gonna do it? so much typing of extra code 😁 so much work. Just basic lazy loading is enough.

  • @Peshyy

    @Peshyy

    11 ай бұрын

    @@harris.sensorsoffline6419 I see you don't care about UX at all

  • @harris.sensorsoffline6419

    @harris.sensorsoffline6419

    11 ай бұрын

    @@Peshyy It won't be ideal, to work on a ldiotic Blur Image Lazy Load when native lazy load is faster & better.

  • @Peshyy

    @Peshyy

    11 ай бұрын

    ​@@harris.sensorsoffline6419 native lazy loading is still being used. the difference is that with one, you get images pop out of nowhere on slow networks; with the other - the images are placed where they should be, the user is visually aware there's an image there and how it should look like, and gets nice visual feedback that the image is being loaded. calling it "idiotic blur image lazy load" shows a lot about you

  • @harris.sensorsoffline6419

    @harris.sensorsoffline6419

    11 ай бұрын

    @@Peshyy If you are working on a Gov Project that requires support for Slower Network & Older Browsers. You can't even support native lazy loading better luck with Tables to align those IMGs 😁. Just kiddin, like you can convert all your images to webp with extreme compression & native lazy loading. Enough, to work good on all 4G Connections that most World runs on.

  • @mrnabby4178
    @mrnabby417811 ай бұрын

    I was waiting for this video.

  • @whonayem01
    @whonayem0111 ай бұрын

    That's awesome!

  • @debugpro
    @debugpro11 ай бұрын

    thats what i want thanks very much i had same porblem in my real portfolio

  • @temperkan3727
    @temperkan372711 ай бұрын

    This guy is awesome!

  • @PeriklesPeriklesoglu
    @PeriklesPeriklesoglu5 ай бұрын

    thank you

  • @dragonspirit254
    @dragonspirit25411 ай бұрын

    I would also add a blur filter to smooth out those low res jpeg artifacts.

  • @faresanalissyahad4468
    @faresanalissyahad446811 ай бұрын

    love the content

  • @BloodyScythe666
    @BloodyScythe66611 ай бұрын

    nice video! one thing I'd have done differently is, if you're using javascript anyways, I'd have set the small image style in the script itself too, to have the DOM be less cluttered

  • @SenselessUsername

    @SenselessUsername

    6 ай бұрын

    Also to make the no-scripts users see the actual picture eventually...

  • @TehPwnerer
    @TehPwnerer11 ай бұрын

    In the 90s with JPEG they would load exactly like you describe and they can because the the way jpegs are constructed using frequency data so you can load lower frequency components first making up a blurry pixelated image like you have slowly transitioning into the actual image as finally received and loaded

  • @mohammadmahdimohaveri6580

    @mohammadmahdimohaveri6580

    11 ай бұрын

    What you're describing is called Progressive JPEG, normal JPEG stores image block by block and cannot be rendered Progressively, but Progressive JPEG stores data from lower frequencies to higher ones, so it can load in an un-bluring manner

  • @alex_smallet

    @alex_smallet

    9 ай бұрын

    Yes, it's called jpeg 2000. Unlike regular jpeg, where they use Fourier transform, jpeg 2000 uses wavelet transform, which allows for better perceived image quality with smaller file size. Windows does not support it, but on a macOS you can save an image in jpeg 2000 format.

  • @yalewjemberu6821
    @yalewjemberu68216 ай бұрын

    Your are the life saver....the (img.complete) one

  • @rabihmaroun225
    @rabihmaroun22511 ай бұрын

    Very useful. King.

  • @blikardo
    @blikardoАй бұрын

    Great video as usual. What do you think of the use of 'skeletons' while loading stuff. Is it any better than having to have multiples files of the same image but sized down?

  • @errorerror1337
    @errorerror133711 ай бұрын

    Love this man, awesome video! Can you please do a vid on requestAnimationFrame()?

  • @avivperets7360
    @avivperets7360Ай бұрын

    Thanks again man! can you made also one video about file types? webp and avif versus jpeg also svg can be nice

  • @HuynhLuong227
    @HuynhLuong22711 ай бұрын

    Thank you

  • @JoseRuiSantos-ruisoftware
    @JoseRuiSantos-ruisoftware11 ай бұрын

    If you already know the image dimensions before loading it, then you should add the width and height attributes to you img. This avoids the annoying effect of seeing the content moving around during image loading

  • @YuriG03042

    @YuriG03042

    11 ай бұрын

    also known as CLS, which is Cumulative Layout Shift, which will impact the page SEO ranking

  • @thalisonamaral1642

    @thalisonamaral1642

    11 ай бұрын

    @@YuriG03042 What do you mean ? using width and height impact SEO ranking negatively?

  • @JoseRuiSantos-ruisoftware

    @JoseRuiSantos-ruisoftware

    11 ай бұрын

    @@thalisonamaral1642 It is the other way around. Not using width/height affects the SEO ranking negatively and increases the cumulative layout shift score. Google for "cumulative layout shift"

  • @rproctor83

    @rproctor83

    11 ай бұрын

    ​@@thalisonamaral1642 After 20 years fuckig around with Google bullshit I can tell you without a shadow of doubt that most all of these SEO tips are an utter waste of time and effort. If you ever look at some of the top ranking sites in highly saturated market you will see most of them are trash, a million console errors, dozens of tracking cookies, elements jumping around, interstitials and popups, bad semantics, too much advertising blocks, shallow content, meaningless content, duplicated content, I mean the list goes on.

  • @thekwoka4707

    @thekwoka4707

    11 ай бұрын

    @@rproctor83 no, it's just that being the thing people want is always most important. But layout shift is still annoying for users period.

  • @arman369world
    @arman369world11 ай бұрын

    It was great and useful, thank you. How can I load the photos myself? For example, load photo number 3 first and then photo number 8?

  • @allenzhao5216
    @allenzhao52169 ай бұрын

    The issue with this puts more load on the user and the server. You're loading multiple images at the end of the day. I would love to see if there could be a version where it automatically downscales itself, and builds upon itself. Great video!

  • @cool_scatter

    @cool_scatter

    6 ай бұрын

    The "load" of a

  • @jubinkashyap5027
    @jubinkashyap50277 ай бұрын

    ❤❤❤thank you

  • @user-qd2sd4mx2k
    @user-qd2sd4mx2k11 ай бұрын

    good video thanks

  • @QwDragon
    @QwDragon11 ай бұрын

    1. You can set background on an img itself. But I think it'll be impossible to add pulse over it. 2. Seems like progressive jpeg (especially with http2) could've solve the problem too? 3. 08:48 I like this more than blurry until load. 4. 10:30 It would be better to specify { once: true } so that it usubscribes after event occures.

  • @user-kq7qg9db7g
    @user-kq7qg9db7g11 ай бұрын

    Web Dev is the best👍

  • @Abdallah_Ismail
    @Abdallah_Ismail11 ай бұрын

    Thank god programming is like an open-book exam, you just need to know that it can be done and you will have Kyle here to help you do it

  • @DaBigin
    @DaBigin11 ай бұрын

    This video is 🔥

  • @user-fed-yum
    @user-fed-yum10 ай бұрын

    So impressed with your skills, every single piece of content you produce. Just a heads up, that addEventListener will leak memory. Simplest fix would be to add an option argument with once:true.

  • @cookieman.19

    @cookieman.19

    8 ай бұрын

    Is that the third argument?

  • @user-fed-yum

    @user-fed-yum

    8 ай бұрын

    @@cookieman.19 Yes, add { once: true } for the third argument 👍

  • @vuongqtvn
    @vuongqtvn11 ай бұрын

    😍 nice sir

  • @asheryramtetteh-abotsi2157
    @asheryramtetteh-abotsi21578 ай бұрын

    What if you are querying the images from a database, how would you implement the blur in case it takes time to load

  • @berkaybakacak
    @berkaybakacak11 ай бұрын

    You are a savior :D

  • @draftermyself
    @draftermyself11 ай бұрын

    Cool! 👍

  • @Buster475
    @Buster47511 ай бұрын

    Considering that jpeg encodes in 8x8 blocks, maybe 16x16 or 24x24 pixels would work better?

  • @Jdinrbfidndifofkdndjoflfndjdk
    @Jdinrbfidndifofkdndjoflfndjdk9 ай бұрын

    Thank you next/image for not making having to write all of this :). Great video btw.

  • @lapridagaspar
    @lapridagaspar11 ай бұрын

    Cool! I personally prefer not having extra markup. You can have the background image directly on the img tag. You wouldn't have the exact fade in animation you achieved but if you save your images with "progressive" turned on, they load in waves of less quality to more quality instead of top to bottom. Also, I think that hiding images by default isn't very progressively enhanced. You could instead add a class when JS starts running to hide them, or the classic remove the .no-js class on the body. Also, wouldn't it be more performant to do the pulse animation with opacity rather than changing the background color value? I think this can be done without extra markup as well (there's no need even for a pseudo element)

  • @lapridagaspar

    @lapridagaspar

    11 ай бұрын

    One more thing. In your example it doesn't really matter, but for regular block images (not on a grid like yours) lazy loading can cause layout shift. To prevent this, you should specify each image width and height attributes. What's more, if you have those values and you are dealing with responsive images, you could also set a style with --_img-width and --_img-height custom properties. This should be the pixel value without unit. Then, in your CSS img[loading="lazy"]{ max-width:100%; height:auto; aspect-ratio: var(--_img-width) / var(--_img-height); }

  • @aniketpandey2524

    @aniketpandey2524

    11 ай бұрын

    while trying this out i ran into said issues and after struggling for 20 minutes I arrived at almost the same solution you gave except for the progressive part. Have no idea what that means. Can you please explain?

  • @PhoenixXxXx91

    @PhoenixXxXx91

    11 ай бұрын

    @@aniketpandey2524 Progressive images, supported since ages from jpg format include the small image Kyle generates inside the image itself. Also, the top-to-bottom loading is different on this kind of images - the same effect we're trying to have in the video, except that it is browser native, rather than using JS. I personally create the progressive images with the "export for web(legacy)" using the "progressive" option in Photoshop, but pretty sure you can find a free tool for that.

  • @aniketpandey2524

    @aniketpandey2524

    11 ай бұрын

    @@PhoenixXxXx91 oh! Now I got it. I thought he's talking about some new option in img tag of html.. 😅

  • @lapridagaspar

    @lapridagaspar

    11 ай бұрын

    @@aniketpandey2524 JPGs can be saved as "progressive" from photoshop. I'm sure there are other ways, but that's how I do it. If you are going full on optimization you may also consider a tag with the image inside as a WEBP or any other modern web format; with the JPG fallback. I don't know if WEBP has this "progressive" option.

  • @Booyamakashi
    @Booyamakashi11 ай бұрын

    Thanks, ill just use progressive jpegs.

  • @csisyadam
    @csisyadam11 ай бұрын

    1. Would ".blur-load:not(.loaded)::before" work? 2. What do you think about "animation-direction: alternate"? 3. Setting the bg color to white and play with the opacity in the animation is another way to do it.

  • @uwu-zl6tq

    @uwu-zl6tq

    10 ай бұрын

    ok

  • @WadieGamer
    @WadieGamer11 ай бұрын

    Welcome back

  • @gwemula
    @gwemula11 ай бұрын

    Hey Kyle. The component in Next.js take care of this problem?

  • @1gabrielroman
    @1gabrielroman11 ай бұрын

    It is a sexy solution. But after I've tried it I found something a bit fancier with less boilerplate. Try to use Verlok's vanilla-lazyload (only 2kb) with on-the-fly generated svgs (you can put the loading animation inside the svg template). It ends up having a bit more bytes around (400b to 2kb depinding on resolution) but the fun thing is it only requests it once for each resolution. So in your example you can use a standard 500x500 svg and you would have 1 request for the loading and the placeholder.

  • @dailydoseofchocolate9411
    @dailydoseofchocolate94115 ай бұрын

    Please make a video about next image too? My problem is how to set height on dynamic images in next js without them losing the aspect ratio and keeping the responsiveness

  • @ZackPyle
    @ZackPyle11 ай бұрын

    You could also throw a filter blur on it to make that pixilated small file look a little nicer

  • @gowthammurugan6392

    @gowthammurugan6392

    11 ай бұрын

    Actually, you are right, but when we use the 'Filter blur' effect on the mobile version, it feels laggy.

  • @ZackPyle

    @ZackPyle

    11 ай бұрын

    @@gowthammurugan6392 Interesting. Which part feels laggy?

  • @sengarnikhil
    @sengarnikhil11 ай бұрын

    I am curious to know, if we set content to none. But left animation there. Will it take any computation load as animations are cpu intensive. Or browser intelligently will remove the animation property if no content is there

  • @imluctor5997
    @imluctor599711 ай бұрын

    question, does this have to do with downloading the image or rendering? Because wouldn’t it look better if it just shows an icon that its loading and then renders it instantly on the screen once it fetched it from the database (or wherever it came from)?

  • @juergenstenzel7300
    @juergenstenzel730011 ай бұрын

    very nice 🙂

  • @tasahik
    @tasahik9 ай бұрын

    Great, jusst consider jpeg is based on su regiones of 8x8 size. So is better if you use widths and heights of smaller images that are multiples of 8.

  • @jimbien7820
    @jimbien782011 ай бұрын

    Hi, I think there is a mistake in your blog article with this : const blurredImageDiv = document.querySelector(".blurred-image") instead of class .blurred-img Thanks for your work and tips ;-)

  • @Chalisque
    @Chalisque11 ай бұрын

    What is the right way to ensure that the placeholder div is the same size the image will be, once loaded, to avoid jerky reflow issues.

  • @canarymultimedia
    @canarymultimedia11 ай бұрын

    What happened to progressive jpg anyway? That was a really cool feature built into the image...

  • @tom3f

    @tom3f

    11 ай бұрын

    It should still works, and it is much simpler than this.

  • @lapridagaspar

    @lapridagaspar

    11 ай бұрын

    That would still start the resource download on page load even if the image is 200 viewport a down.

  • @mohammadmahdimohaveri6580

    @mohammadmahdimohaveri6580

    11 ай бұрын

    You can lazy load progressive jpeg as well, and this way you're not wasting user's bandwidth for blurred images, image actually loads progressively and you won't have to manage two sets of assets

  • @GonzaloMassa

    @GonzaloMassa

    11 ай бұрын

    I was looking for this comment

  • @93kumite
    @93kumite11 ай бұрын

    Hey Kyle I've a question According to you, what are the fundamental concepts of Computer science a web developer ( let's say full stack developer) should know ? Thanks

  • @mukhtarhussain8954
    @mukhtarhussain895411 ай бұрын

    amazing

  • @bytebeamer
    @bytebeamer9 ай бұрын

    Just wondering how he pasted into multiple lines at the same time?

  • @mrnabby4178
    @mrnabby417811 ай бұрын

    wow no library or framework. You are awesome man.

  • @reyzonchhetri301
    @reyzonchhetri30111 ай бұрын

    How to do it dynamically fetching from backend

  • @niklausmikaelson7332
    @niklausmikaelson733211 ай бұрын

    Is there anyway to trigger Horizontal Intersection using the intersection Observer?

  • @goodluckoriuwa1669
    @goodluckoriuwa16697 ай бұрын

    This is good to know.... But one more thing... Can you show how to implement this feature in react front end application???

  • @uttamsharma3242
    @uttamsharma324211 ай бұрын

    how would you be handling if the height is not fixed size of Img?