Do This to Improve Image Loading on Your Website

Поділитися
Вставка
  • Опубліковано 29 лис 2024

КОМЕНТАРІ • 79

  • @HazimSami
    @HazimSami 5 років тому +90

    Jen, you are doing an outstanding job with the team at Mozilla. Thank you all for the great content on this channel. Keep 'em coming 😊

    • @gradybraylen3569
      @gradybraylen3569 3 роки тому

      i guess im randomly asking but does someone know of a way to log back into an instagram account??
      I somehow forgot the account password. I love any tips you can offer me

  • @AmandeepSingh-hd8iq
    @AmandeepSingh-hd8iq Рік тому

    Watching Jen's video is more addictive than watching Netflix. Supreb content with amazing explanation. Thank you so much.

  • @VRwithAndrew
    @VRwithAndrew 5 років тому +21

    I'm not a web developer. But, I find these videos incredibly interesting and well put together.

  • @biboswanroy6699
    @biboswanroy6699 4 роки тому

    Watched and applied it immediately on my website. Boom experience is so much better now

  • @swampflux
    @swampflux 5 років тому +35

    height: doggo

  • @wellsdorian07
    @wellsdorian07 5 років тому +4

    Thank you for the help to stop "Janky" sites!

  • @PhillipStewartYYZ
    @PhillipStewartYYZ 3 роки тому

    Great video, thanks. Whenever I see image size not reserved for images and web pages I think what is wrong with these people the solution has been in place since 1995. Always include height and width on IMG.

  • @MarcWorrell
    @MarcWorrell 4 роки тому

    Thanks! This is now being added and tested in the open source CMS Zotonic.

  • @joshdeltener-work
    @joshdeltener-work 3 роки тому +1

    What was the result of the convo? It's been 2 years and I haven't heard anything.

  • @sheriffderek
    @sheriffderek 5 років тому +1

    This makes sense - and I know the aspect ratio in many situations... but in a lot (leaning towards 'most') situations - I'm not going to know the height of a given image in a CMS. For example a poster image on a single resource page (say, a blog) - I'll set width but allow the client to shove whatever in there. But - the CMS knows the image size - so I guess you just have to draw the line on how each image works. Good info! I think this will be useful in 30% of cases for me. Especially grid type images. The rest usually involves a lot of the contextual image switching.

  • @sylkates
    @sylkates 4 роки тому +1

    Can't wait for a CSS aspect ratio property. It would make so many time consuming styles faster to write.

  • @youngun550
    @youngun550 Рік тому

    Fabulous video. I'd really appreciate your expertise in answering a couple of questions if you have the time!
    If we want to use different pictures of different sizes according to a screen break. What would be the best way to approach this.
    For instance


    The issue above is that I can provide height and width for the mobile image, but if the user loads on the desktop, I don't understand yet, how to provide fixed width for that.
    Would love to hear your thoughts on this! Thanks

  • @quicktastic
    @quicktastic 5 років тому +2

    Looking at the last part there with multiple images, it looks like you could just simply put the aspect ratio in pixels in the html sizing. For example.. width="16" height="9" or whatever. It could actually be helpful for quickly identifying the aspect ratio when looking at it later. Now I have to go experiment. :)

  • @jackwright7014
    @jackwright7014 4 роки тому +5

    Automatic aspect ratios without JS... 🤯 Thanks goodness!

  • @Yoni-G
    @Yoni-G 5 років тому

    Thanks for this very informative video. The dilemma with all brand new techniques is that the average user may still have a slightly older browser, and I don't mean IE6, but maybe a browser that has not been updated for a year. So, unless your audience is tech-savvy, it may be worth waiting a bit before applying these techniques.

  • @liho26
    @liho26 5 років тому +3

    @Mozilla Developer Hi Jen! Thank you for nice content on your channel. One small question. When Mozilla will start supports subgrid for CSS Grid?

    • @liho26
      @liho26 5 років тому

      @@MozillaDeveloper Nice! Many thanks!

  • @JSBroadcast
    @JSBroadcast 5 років тому +1

    Hi Jen, and thanks for another great video. To go slightly off-topic, are we ever getting a fallback image attribute for , in case image provided to the src for whichever reason fails to load? Of course, we handle all this stuff either using some hacks or with JS, but I think it's time that we actually get an attribute e.g. src-fallback to which we can provide a default image if the src one doesn't load. Any thoughts? Thanks.

    • @JSBroadcast
      @JSBroadcast 5 років тому

      @@MozillaDeveloper The thing I'm mentioning solves a problem that for whatever reason an image doesn't load e.g. was removed from the server, it would get replaced by some default placeholder image. You can see those examples all over the internet (primarily social platforms) and the way we solve it right now is with JS e.g. if an image returns 404 or if there's an error in general, you replace the image with a placeholder image. This is to keep the UI not show that ugly image missing icon, pretty much ruins the UI when it happens.

    • @robertlinder8464
      @robertlinder8464 5 років тому

      See these related issues: github.com/whatwg/html/issues/3858 + github.com/w3c/csswg-drafts/issues/656

  • @RaveYoda
    @RaveYoda 3 роки тому

    I didn't know srcset existed...huh...very cool!!

  • @BoydWaters
    @BoydWaters 4 роки тому +1

    Awesome! It works! Super helpful. THANKS

  • @CraigBuckler
    @CraigBuckler 5 років тому +1

    This is great news, thanks. Will the aspect ratio also be calculated for width and height attributes on `` and `` elements as well as ``? In fact, could widths and heights be applied to any block-level element?

  • @xGSTQ
    @xGSTQ 4 роки тому

    This is awesome! Still going to have to support older browsers though for now, so I'm still going to tap into the fluid container with padding hack for lazy loading assets

  • @SeanGoresht
    @SeanGoresht 5 років тому

    If you're already using srcset AND sizes, would specifying the image width and height be necessary?

  • @richpeacock
    @richpeacock 4 роки тому

    I love geeking out with Mozilla. Everyone seems like people I would have been pals with before the media went divisive in 2016 and split the world into two.

  • @jimbo2150
    @jimbo2150 5 років тому +1

    Great video and glad to hear Firefox will be calculating aspect ratio on it's own - as well as working on a css property to allow developers to define a custom one!
    I would also like to know how to have an image load the appropriate sized image for the container (the size of the img/picture element). I know srcset primarily uses the viewport size but what if you have an image that is the size of the viewport (or close enough with a bit of margin/padding) on a mobile device but then want it to only be a maximum of 300px width when on a 1080 monitor? Since it goes by viewport it will load the 1080w image instead of the 300px that the img element is limited to.

  • @avneet12284
    @avneet12284 5 років тому +1

    Really good 👍. Thanks Jen

  • @PeriMoritz
    @PeriMoritz 5 років тому +4

    I have a thought/question, and this is browser support aside. If I use the width/height of 1/1 or 2/4 or 5/7 or 16/9 would that suffice to support the aspect ratio feature coming with Firefox 71? Throw in an Object-fit: cover? Just thinking out loud for possible more flexible options.

    • @toddeaster3652
      @toddeaster3652 5 років тому +1

      I had the same thought about object fit.

    • @jimbo2150
      @jimbo2150 5 років тому

      I had the same thought and it believe would also go to art direction point. Some people may be fine with using object-fit: cover but some may not want the image to cut off some potentially important parts of an image that may be closer to the edge and may instead want to define their own custom aspect ratios so that the entire image always displays rather than being clipped or expanding outside the img/picture element.

    • @malydok
      @malydok 5 років тому

      Doesn't adding `object-fit` negate the thing that this feature is trying to introduce? With `object-fit` you're deffering the image size to be determined by the size of its container.

  • @patrickc.6183
    @patrickc.6183 5 років тому +2

    Great video Jen! Are there any plans to bring native lazy loading of images to Firefox?

    • @jimbo2150
      @jimbo2150 5 років тому +2

      Also my thought, and I am sure it is on the docket for a future release. Correct me if I am wrong but I don't believe this is part of the HTML standard - yet. I think it is just a draft made by a Chrome dev and so far has only been adopted by Chome/Blink. I am sure it will eventually be adopted by the HTML spec and other browsers will begin adding it.

    • @RickBeacham
      @RickBeacham 4 роки тому +1

      Its in the works on firefox but there are some build errors. Also, webkit has build errors as well. Probably the most popular new feature on chrome currently.

  • @mohamedhussainsh7913
    @mohamedhussainsh7913 4 роки тому

    Thanks for this, do we have any caniuse page to check the state of this feature in different browsers?... and will this applicable to normal elements if not , we left with padding hack to give the proper aspect ratio without jank

  • @JonathanLaliberte1
    @JonathanLaliberte1 5 років тому +1

    Very cool! Thanks for the info!

  • @rgilmour70
    @rgilmour70 5 років тому +1

    This is very useful! Many thanks!

  • @milindkhadse556
    @milindkhadse556 4 роки тому

    Great video. Thanks to upload :)

  • @th34lch3m1st
    @th34lch3m1st 3 роки тому

    What happen if I have to set dimensions with vh an vw?

  • @progtom7585
    @progtom7585 4 роки тому +1

    this content is great, thanks heaps!

  • @jagc2206
    @jagc2206 5 років тому

    Hmmm,
    I am really conflicted on the height/width not being in pixels but when you don't have it set to auto in css it will also be the height in pixels.
    I guess it used to make sense when css wasn't really a thing, but does it still make sense?

  • @sankalp_choudhary
    @sankalp_choudhary 5 років тому +11

    Love mozilla

  • @selfishprimate
    @selfishprimate 5 років тому +1

    Something like this:
    .responsive-img{
    height: attr(data-ratio);
    }

  • @JeffBachtel
    @JeffBachtel 5 років тому

    Hi Jen I know you're active on Twitter so you might have noticed - I upgraded to FF 71.0 after watching your video and the twitter.com web interface seems to be waaaay more jank (presumably due to image loading). Have you noticed a change? Is this just something Twitter's gonna have to fix with image tags?

  • @benjaminli21
    @benjaminli21 5 років тому

    But... I might be wrong or misheard what you said... Aren't settings image width and height explicitly in the HTML tag makes the image not responsive?
    OK, I need to rewatch to see if I missed anything... (I kind of thinking that width:100% and height:auto in the CSS is what doing the responsive magic even we set width and height attribute explicitly in the HTML tag...
    And thank you for the sharing! Good job!😆

    • @benjaminli21
      @benjaminli21 5 років тому

      Hmm... I get that now... In older browser you can't get both (the solution of jankness and responsiveness) to work but the newer browser will try to grab the info of image and make a ratio and save our lives 😁 well, thanks! But if the solution is only work on newer browser, I think we better come up a backward compatible solution...
      Anyway thanks 😁

  • @wpezdeveloperdot_com1301
    @wpezdeveloperdot_com1301 5 років тому

    Height and width? Ha! What more people need to understand is sizes and scrset. One of the main reasons images lag is because the value of the sizes attribute is suboptimal. This is especially true with WordPress. Removing the jank is nice. But an empty slot isn't a great UX either.

  • @FrankEBailey
    @FrankEBailey 5 років тому +4

    Huh! Everything old is new again :D

  • @nikhilsharma2236
    @nikhilsharma2236 Рік тому

    why dont just add new attribute named maintain which maintain the aspect

  • @MichaelLockhart
    @MichaelLockhart 5 років тому

    Since the units for width= and height= are unspecified, and it's only the ratio between them that seems to be important, could we just express it as a ratio in the img tag?
    width="15" height="10" in this case?
    Well, only if we also use the CSS height: auto
    For Firefox, with this update, that would work. But for other browsers, or Firefox 69-70, I think the "jank" would return. In cases where there's no CSS height auto, the browsers still interpret it as pixels, so it would make the space 10 pixels high to begin with. :(

  • @cotojesakra
    @cotojesakra 4 роки тому

    So is this Firefox only solution?

  • @castletown999
    @castletown999 5 років тому

    Would it not be better to include the image dimensions in a header that can be fetched from the server quickly, without waiting for the entire image?

    • @castletown999
      @castletown999 5 років тому +1

      @@MozillaDeveloper I understand. But the problem with it is that the image information is in two places. It's in the image file and in the HTML. If I want to substitute a different image I have to change the HTML too. This is not normal form (where a given piece of information should be stored in one place only - to avoid them getting out of sync) . I have a site where some images are in multiple places, so this gets to be major chore. I have to run around trying to remember all the pages that use it so I can modify the size attributes.
      What would be REALLY cool is if the server could include the image sizes of all the images on the page in the page header. Sure, it would only get the static images but it would still help a lot.

  • @funkologie
    @funkologie 5 років тому

    Wondering what I can do, whitout to know width and height...

  • @Andrey-il8rh
    @Andrey-il8rh 4 роки тому

    Is there any update with width/height on the element? It's already almost a year passed, I need it badly 😢

  • @diegovadell5707
    @diegovadell5707 5 років тому +2

    Thanks!! :D

  • @selfishprimate
    @selfishprimate 5 років тому

    Wouldn't it be much easier to use some kind of HTML attribute like aspect-ratio="16:9"? Or some data attributes can be used to fix that like data-ratio="16:9". I think it will be much human-readable and semantic.

  • @oguzakankan518
    @oguzakankan518 5 років тому

    Where have you been? 😄

  • @alikin
    @alikin 4 роки тому

    2020 now! And this technique now works for any browser like latest version of Chrome and Safari?

    • @MinasKeshishyan
      @MinasKeshishyan 4 роки тому

      It works for Chrome and Firefox, but not for Safari.

    • @MinasKeshishyan
      @MinasKeshishyan 4 роки тому

      @@MozillaDeveloper awesome!

    • @ahsath
      @ahsath 4 роки тому

      @@MozillaDeveloper Where can we see support for this in Safari?

    • @JenSimmons
      @JenSimmons 4 роки тому +1

      @@ahsath This change shipped in Safari 13.1 this spring. I'm not sure where I can point you for documentation - for instance, this isn't really a new 'feature' that's listed on Can I Use - but I know from talking to engineers that this has definitely shipped in Safari, as well as Chrome, Edge, and Firefox. Testing should show as much.

    • @ahsath
      @ahsath 4 роки тому

      @@JenSimmons yep, it ain't a feature here's some mdn docs for it developer.mozilla.org/en-US/docs/Web/Media/images/aspect_ratio_mapping thanks for let it me know that's is available for safari

  • @MouhamadouDer
    @MouhamadouDer 5 років тому

    Great video!

  • @ThomasKempDesign
    @ThomasKempDesign 5 років тому

    Will this work if you use compressive imagery?

  • @cristopher5837
    @cristopher5837 5 років тому

    What if we don't know the actual aspect ratio of the image?

    • @cristopher5837
      @cristopher5837 5 років тому

      ​@@MozillaDeveloper Thank You for for your answer Jen! I wish I knew this before

  • @aaronharding3695
    @aaronharding3695 4 роки тому

    hey Jen! how would you support images with variable widths in this way? if the image in the html is `` what would happen if the css applied was `width: 100%; height: auto;`?

  • @Foguest
    @Foguest 3 роки тому

    💪

  • @xerzy
    @xerzy 5 років тому +1

    I feel like this is going to become troubling... I bet people are just going to put something like width="16" height="9" and it'll be a mess 🤔
    Anyway, thanks a lot!

    • @xerzy
      @xerzy 5 років тому

      @Still waiting for Fry Retrocompatibility, in essence, where old browsers are not going to render things properly

    • @MinasKeshishyan
      @MinasKeshishyan 4 роки тому

      ​@@xerzy How old should be a browser to not use width / height applied by css?

  • @psfdek
    @psfdek 4 роки тому

    Давно пора!