Тёмный

Teaching CSS to a Coder 🙀 (How to Lazy Load Images) 

DevTips
Подписаться 353 тыс.
Просмотров 30 тыс.
50% 1

Sponsored by: ForkLift, thanks! Try the most advanced file manager and file transfer client for macOS and use the coupon code DEVTIPS to get 50% off. bit.ly/2IwUBMT
David teaches MPJ about lazy loading images for better mobile performance and the CSS aspect-ratio box padding trick. MPJ is NOT convinced.
Can you solve it in a different way - write that in the comments plz!
Aspect-ratio boxes on CSS Tricks has covered this hack in great extent.
😎 css-tricks.com/aspect-ratio-b...
To properly access the DOM in React, we should have used refs (thanks to @23luski and @Rela takera in the comments)
☝️ reactjs.org/docs/refs-and-the...
The editor is called Visual Studio Code and is free. Look for the Live Share extension to share your environment with friends.
💻 code.visualstudio.com/
DevTips is a weekly show for YOU who want to be inspired 👍 and learn 🖖 about programming. Hosted by David and MPJ - two notorious bug generators 💖 and teachers 🤗. Exploring code together and learning programming along the way - yay!
DevTips has a sister channel called Fun Fun Function, check it out!
❤️ / funfunfunction
#css #hack #reactjs

Опубликовано:

 

8 ноя 2018

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 168   
@TheNeonRaven
@TheNeonRaven 5 лет назад
You could also have just put an actual image element inside the wrapper div without resorting to JS dom insertions. If you don’t want the image to show up at all until it’s fully loaded, then just give it 0 opacity, and use the images onload event to set the opacity to 1. This also lets you put a transition on it if you’d like, and if you have width and height attributes on the images, then this will force the size of the wrapper for you so you don’t need to hard code it in the CSS. Slightly more performant, more accessible, image can now be picked up by search engines, and arguably easier to reason about. :)
@cameronwarje4203
@cameronwarje4203 5 лет назад
Amazing suggestion.
@mubarkmurtda4735
@mubarkmurtda4735 5 лет назад
😍😍
@s.daniel2714
@s.daniel2714 4 года назад
This is actually quite nice. I will use this. thanks
@librev5881
@librev5881 5 лет назад
Thanks for the DevTips, these videos are really helpful for those looking to use CSS when designing their websites.
@CodeGoblin
@CodeGoblin 5 лет назад
This was very enjoyable to watch, love the fact that you guys don't do this before hand so that we get to see how you approach the problem realistically.
@whoami-so2hy
@whoami-so2hy 5 лет назад
i always watching u in every episode cz i enjoyed:)
@raipratik
@raipratik 5 лет назад
Loved it guys. Keep dropping SEO boosting hacks. Now its time for FIKA!!
@mattjclay
@mattjclay 5 лет назад
“A cpu is just a rock that we fooled into thinking, then we put lightning inside of it.” Love it. So elegantly put.
@md.akib5124
@md.akib5124 5 лет назад
DevTips Pair programming is so cool. It's helping me to learn how to work with other programmers in a team. I really like the style how you go through the project just as we go through in practical life
@shriniwasrocks
@shriniwasrocks 5 лет назад
this is an awesome video format. Please do more of these challenges.
@nenojay6832
@nenojay6832 5 лет назад
This is awesome, I love learning how others approach problems like these.
@nathantorquato9777
@nathantorquato9777 5 лет назад
A couple of mates complaining about the channel's content quality. IMO it's great for new devs to see what real life coding is like. Every seasoned dev knows this is actually what our life is like. It's just a matter of target audience. That's definitely not a channel for senior devs. I'm a huge fan and have been subscribed since Travis. It's still a great channel with awesome content... a different approach though. keep up the good work, mates!
@chrsbll
@chrsbll 5 лет назад
Padding percentages being relative to element width actually makes a lot of sense. You don't want it relative to height because then setting the padding top or bottom would affect its rendered height and you'd have to recalculate the padding, and so on.
@ankushjamdagani2879
@ankushjamdagani2879 5 лет назад
We all have so many sources for serious learnings and stuffs, including you guys, But I keeps on sticking here... to the FFF and DevTips only because it gets boring sometimes and I watch you guys for the fun in learning. That way it sticks in your head for long. Instead of G.O.T., I am watching you guys, coz it's more fun and involving. Thanks for the efforts and innovation guys are bringing in.
@wuiqed
@wuiqed 5 лет назад
"I am shit today, thank you."
@wojciechlipinski7258
@wojciechlipinski7258 5 лет назад
So I'm at work, writing ReactJS, watching your video, listening to music. It's not easy to be a JS programmer 😁😁😁
@GifCoDigital
@GifCoDigital 5 лет назад
Was literally just working on this yesterday! You could also have had a handleImgLoad() method on your class, then use an img tag inside your image container with display none. Then on the img tags onload() event you can display block to reveal the img. You img container handles the svg img like you are already doing it.
@pureretro5979
@pureretro5979 5 лет назад
As the old man in the room who has been doing this since the days of dialup I say bring back the lowsrc attribute. It loaded the low res image and then got to work on the huge 6Kb image once it was done. :-)
@OfficialDevTips
@OfficialDevTips 5 лет назад
Whaaat didn’t even know about that. And yes. These heavy 6 kB files is really hurting me on the 1 Gbit fiber.
@leonk6950
@leonk6950 5 лет назад
Is that a thing in the current spec?? Sounds like something that should be used everywhere, as long as the implementation is good
@IvanIvanov-ep8zo
@IvanIvanov-ep8zo 5 лет назад
12:00 Little known fact - in CSS when setting the padding of element in percents, the value is calculated based on the width of the parent element, and not the width of the Element the padding is set on. Having this in mind I would recomend creating pseudo-element (:before or :after) and set the padding there, this way the height will be propotional to the element itself. This technique is used when making responsive videos - first we create div and apply padding-ratio of 16:9 (the video's ratio) or 56.25%, then we make it with relative position, and then we position absolutelly the video element inside. That makes the video element keep the ratio of it's parent element, and we avoid having black bars on the sides or on top/bottom of the video.
@mikeendsley8453
@mikeendsley8453 5 лет назад
Иван Иванов this! This is exactly what I do and it works like a champ.
@juliovedovatto
@juliovedovatto 5 лет назад
Thanks for the insights guys, it was helpful
@sweLogan
@sweLogan 5 лет назад
CSS pervs 😂
@DEVDerr
@DEVDerr 5 лет назад
CSS hack is like "Excuse me... What the f&ck?"
@josephmallari8780
@josephmallari8780 5 лет назад
You could also use the new Suspense and Lazy feature on the latest React release. Set the low quality image, then append the high res image once it's loaded.
@jesinu
@jesinu 5 лет назад
Thanks guys, I enjoyed this. 👍
@idontwantmynameinhere
@idontwantmynameinhere 5 лет назад
12:00 .elem { height: 100vh; /* 100 viewport height, fill screen */ width: 100vw; /* fill screen */ object-fit: cover; /* Does the same thing but seems more reasonable to me than padding-bottom: 150%; }
@81NARY
@81NARY 5 лет назад
Yeah but wouldn't that take the whole height of the screen and push other elements at the bottom (that button in this case) further down? Edit: I think there should be another way around this horrible hack. I still can't wrap my head around padding-bottom 😂..
@idontwantmynameinhere
@idontwantmynameinhere 5 лет назад
@@81NARY Of course, 100vh is equal to 100% (but more reliable on smaller screens). But if you want to have a different value for height, that's totally fine. My point is that if your height and width are fixed, you could use box-sizing: border-box; and using 100vh makes the whole thing responsive, so that's why I chose to use 100vh
@railb1rd
@railb1rd 5 лет назад
object-fit is not well supported though
@81NARY
@81NARY 5 лет назад
@@idontwantmynameinhere Totally agree on that 😊
@Victor_Marius
@Victor_Marius 5 лет назад
height: 150vw; I think they needed
@sahilchutani2200
@sahilchutani2200 3 года назад
If we don't write padding-bottom or height the image will itself take the values and will retain its aspect ratio as well because we have given width 100%
@alphanimal
@alphanimal 5 лет назад
the conclusion @22:20 seems like two drunk guys arguing about the meaning of life. awesome.
@Haydencarnegie
@Haydencarnegie 5 лет назад
I'd action this a different way as background images aren't great for accessibility (since you can't give them an alt or title). I'd make the image wrapper have its padding but make its position relative. The image inside i'd then make position absolute, top 0, left 0, width 100%; height 100%; this shouldn't distort the image as we already know its aspect ratio, if there is an a problem with the image aspect ratio you could end up changing the wrapper have a property of object-fit: cover; That may be new CSS and experimental but that will do the job too.. Devtips, could you do a video on grabbing different images depending on the size of your window/device? Whether speed would be better using a src set or just directly changing the image in the DOM?
@natqe4049
@natqe4049 5 лет назад
Wow, now you start to talk. Thank you very much guys.
@valshin
@valshin 5 лет назад
You've created an Image, and then changed the url of the existing image (background-image). Is the image actually caching?
@brianhogg358
@brianhogg358 5 лет назад
In that specific instance, why not simply use an image tag inside the div? That way the svg background image would still show, and the full-size image would progressively appear (depending on format) without need of any additional JS. Also, you can sidestep some of the needs of the padding-bottom hack if you set the size of the div you want and have background-size set to cover. This would cause some pixels to not be displayed if the image isn’t exactly 3x2, but on the plus side, it makes the layout consistent even if the hypothetical editor in this situation uploads every image with slightly different dimensions.
@reg.x
@reg.x 5 лет назад
You could use the component's state to handle the image loaded status, on the render function you can select the src according to the state, ex: constructor(){ this.state = { showOriginal:false } } ... img.onLoad(() => this.setState({ showOriginal: true })) ... render(){ ... ... }
@23luski23
@23luski23 5 лет назад
You should use refs instead of querySelector...
@23luski23
@23luski23 5 лет назад
But actually the whole idea could be implemented much easier without touching DOM api
@OfficialDevTips
@OfficialDevTips 5 лет назад
I thought refs were only in “old” React. And yeah I’m sure we could use state on the src instead or something. What do you have in mind?
@OfficialDevTips
@OfficialDevTips 5 лет назад
Noo I guess it was STRING refs I was thinking about
@abdullahabd7677
@abdullahabd7677 5 лет назад
I don't know why but I laughed out loud when mattias was attempting to comment out the html inside the js file.
@shauntricks
@shauntricks 5 лет назад
For such a talented man!!! you forgot about CSS { height: Auto ; Viewport vh; height: 100vh; /* 100 viewport height, fill screen */ width: 100vw; /* fill screen */ }
@emmanuel4699
@emmanuel4699 5 лет назад
I was wondering. Is there a reason you guys didn't use "object-fit" and give the image a defined height and width? This was a fun episode.
@Shubham_Gautam
@Shubham_Gautam 5 лет назад
@DevTips How about keeping onload method inside a promise. Initialise promise inside constructor of class or above class. Assign promise to class property, use promise resolve in ComponentDidMount to resolve the promise and update the image url. Though it won't make huge difference but it will be faster than current implementation. I guess :)
@mikejames5918
@mikejames5918 5 лет назад
"A CPU is essentially a rock that we have fooled into thinking and then put light inside of it." MPJ
@JoshuaHeagleDev
@JoshuaHeagleDev 5 лет назад
Oh man, already did thumbs up, we need a second thumbs up or dare I suggest claps? MPJ's disgust at CSS was fantastic.
@elvinnie1985
@elvinnie1985 5 лет назад
Quite like the idea behind these videos: developers trying to figure things out. Quite often there is more to be learned by watching someone fail and learn things, than to just watch someone do it quickly in 1 minute. We can learn from our mistakes. After watching several of your latests videos however, I'm quite often disappointed by the end result. This video is full of bad-practices and anti-patterns, both on the CSS and React side of things. Plenty of commenters have pointed that out already. I get that you have to fight through a load those bad things before ending up with a decent result, and it's perfectly fine to show that in the video, but you're not ending up with a decent result. You're just teaching bad stuff here. Trying to show us a CSS-trick while using React to implement that trick, and then halfway the video admit that you don't really know how it works in React.... Why? Why not just use plain HTML with some small JS-script? Or any other library that you actually know how to use? This just shows a huge lack of preparation, and to be honest, feels a little disrespectful towards your viewers. I would suggest a slightly different approach: make sure one of you really knows the subject, or really prepares for the subject, so you know what the best practices are. Then have the other one figure things out. That way, at least you can make sure you end up with a decent result, and actually teach good stuff, while still getting the cool dynamic of "figuring out things".
@PaulMcCannWebBuilder
@PaulMcCannWebBuilder 5 лет назад
As a CSS perv, I have to agree that would the right approach. It's fun to watch developers figure things out, but this video is only helpful because it forces me to try to think and make a list in my head of all the pure CSS solutions I would have used. And my main goal would have been avoiding delivery of an image bigger than it needed to be in the first place. I don't want you two to stop doing these kinds of 'top of your head' code videos though. Just throw in something useful, like show me how to implement SQIP so it creates placeholders for a folder full of images and then load them properly to the page.
@watching4410
@watching4410 5 лет назад
I think it has to do with the CSS box model and would like to see to use the other parts of the model used as if it was the padding in the code shown. Should try using the margin, (possibly not border), padding (already tried), and content if they work the same. (if so, then it probably has to do with the box model not padding.)
@Thuckmyath
@Thuckmyath 5 лет назад
"oh you mean humans!!!" :D I'm new to programming and I gotta wonder is this my future??? :D getting so caught up in programming terms that I forget the word for humans!!! :D xD
@ksubota
@ksubota 5 лет назад
yes, it is :)
@danko95bgd
@danko95bgd 5 лет назад
Why not object-fit property
@StevenKW
@StevenKW 5 лет назад
Great stuff.
@Victor_Marius
@Victor_Marius 5 лет назад
There's also vmin, vmax, vh and vw!
@maddada
@maddada 5 лет назад
Hey guys, I'm really liking these pair programming videos, please don't listen to the loud minority saying they're not interesting. You'll never be able to please everyone so do your best and don't try to! If you guys feel like it maybe there's room for more rehearsed vids about harder topics but please keep these ones too, they're funny, interesting, and really mirror how real life coding is like.
@GuusHamann
@GuusHamann 5 лет назад
You can use http2 headers to preload the image :-)
@jasperzanjani
@jasperzanjani 5 лет назад
MPJ the reason you make so many typos is because your oversize Nordic hands have too much Viking power for your laptop's tiny chiclet keys. I look forward to hearing the satisfying clackity clak of a mechanical keyboard (green switches) once you have come to your senses
@pavelagarkov2634
@pavelagarkov2634 5 лет назад
Instead of padding-bottom you can use height: 150vw; which is much more understandable - it will be 150% of viewport width. Also using Progressive JPEG might be much easier then writing a code... I personally use generic background image drawn with CSS gradients as a thumbnail and Progressive JPEG on top of it.
@thomashoffmann9349
@thomashoffmann9349 5 лет назад
That's not going to achieve the correct aspect ratio as it's dependent on the height of the window, not the width of the image...
@pavelagarkov2634
@pavelagarkov2634 5 лет назад
@@thomashoffmann9349 sure, but image width in most cases depends on viewport width in one way or another. In my case I do actually use something like this: height: calc(100vw / 3 - 20px); where 20px - is a sum of paddings over the image. but it is hard to say it is well understandable :))
@JacopoPatrocloMartinelli
@JacopoPatrocloMartinelli 5 лет назад
The universe thing broke me... 😂
@mdshoaibAlamgcetts
@mdshoaibAlamgcetts 5 лет назад
Superb
@taneliharkonen2463
@taneliharkonen2463 5 лет назад
Noob here: What Is this cool software/interface that you are working with? :) Coding the same document n stuff! :D
@gioac96
@gioac96 5 лет назад
It's Visual Studio Code, and he's using the VS Live Share extension. 100% awesome stuff.
@ksubota
@ksubota 5 лет назад
In CSS you can`t write something like 'height: 1.5 * width' because of the way a browser interprets layout. For example, imagine you state that hight = 1.5 * width, and width = 1.5 * height, it just can`t resolve it to some finite size. CSS isn`t a procedural programming language, of course you go crazy when trying to pretend it is.
@jameszaccardo1520
@jameszaccardo1520 5 лет назад
you could use the calc function to achieve this
@ksubota
@ksubota 5 лет назад
@@jameszaccardo1520 no, you can`t, because with the calc function you can reference only its parents dimentions, not its own. That`s why they used a hack with padding.
@jameszaccardo1520
@jameszaccardo1520 5 лет назад
​@@ksubota your just doing it wrong
@ksubota
@ksubota 5 лет назад
@@jameszaccardo1520 may you give an example, please?
@szlain
@szlain 5 лет назад
The image should also be saved as 'interlaced' en.m.wikipedia.org/wiki/Interlacing_(bitmaps)
@beeenthere
@beeenthere 5 лет назад
You could definitely turn CSS Pervs into a sticker 😆
@indoom
@indoom 5 лет назад
.src assign should be after .onload assign, or cached images won't fire onload
@ZliNindza
@ZliNindza 5 лет назад
Gotta some feedbacks for you: do more small projects, moar pair programming and shorter videos!
@leonk6950
@leonk6950 5 лет назад
Noooooo longer videos are better
@ViniciusRocha-bl1lk
@ViniciusRocha-bl1lk 5 лет назад
Here, an article about the aspect ratio trick: css-tricks.com/aspect-ratio-boxes/
@thomashoffmann9349
@thomashoffmann9349 5 лет назад
Hey guys... the padding-top / bottom as a percentage is part of the spec, not a hack... Have a look: www.w3.org/TR/2011/REC-CSS2-20110607/box.html#padding-properties: "Percentages: refer to width of containing block". The designers of the CSS language actually put a lot of thought into this, and understanding CSS in the same way you know native JavaScript or HTML is critical to being an effective frontend developer; CSS is one of the most carefully planned out and future proofed languages for layout ever created - truly a work of art. There isn't anything magical or black box about it, it's just that everyone seems to think they can get away with not learning it, and the result, imho, is probably more costly than IE6 ever was...
@RmNrIHRoZSBDQ1AK
@RmNrIHRoZSBDQ1AK 5 лет назад
Percentage padding is not a hack. The worst you can call it is a trick. Since you're locking yourself into a fixed container aspect ratio you really should use background size cover or contain with desired position and no repetition. Backgrounds are also better than image nodes from a performance standpoint (I remember an old Flickr research on that). And if accessibility is of any concern, there's WAI ARIA and microdata. Also, why is the micro image an SVG? Just use a tiny JPEG and base64 inline it.
@OfficialDevTips
@OfficialDevTips 5 лет назад
Tje SQIP looked better than when I generated JPEG LQIPs
@groovebird812
@groovebird812 5 лет назад
How did you create the blurry svg file?
@OfficialDevTips
@OfficialDevTips 5 лет назад
Using SQIP. If you write a simple node application and import that library, it is not too complicated to convert: github.com/technopagan/sqip
@ArthurvanAcker
@ArthurvanAcker 5 лет назад
If you want to know more about why padding-bottom in % works, css-tricks.com/aspect-ratio-boxes/ tells you all need to know
@evans8245
@evans8245 5 лет назад
where do u work mattias
@Ecker00
@Ecker00 5 лет назад
Could have placed the two images on top of each other with position relative/absolute, then there is no need to replace with JS and would fetch as soon as possible. Think that would work? This solution seems a bit over engineered. 😅
@ChristoPy_
@ChristoPy_ 5 лет назад
Just add height: auto; Is much more simple
@laymanan
@laymanan 5 лет назад
Wasn't this the whole point of progressive jpg's?
@petarkolev6928
@petarkolev6928 5 лет назад
Okay, setting padding-bottom to 150% is a hack and works for the wrapper to be the needed height in the first place but how the hell when the image is loaded the padding-bottom disappears?!?
@OfficialDevTips
@OfficialDevTips 5 лет назад
If you add an image within the wrapper, set the wrapper's style to have "overflow: hidden;" Or just replace the wrapper's style "background-image" with the new image, which actually never removes the padding.
@petarkolev6928
@petarkolev6928 5 лет назад
But if I never remove the padding wouldn't this resolve in pushing the button (in your video's case) away down from the image? Or am I just not familiar how padding really works :p
@IkBenMarcelAkkerman
@IkBenMarcelAkkerman 5 лет назад
I think there is no content. The 2x3 rectangle is constructed only with bottom padding. remember the image is the background of the element not the content.
@petarkolev6928
@petarkolev6928 5 лет назад
Marcel Akkerman ooooooh, background! Yes, my mistake! Now it does make sense:)) thx ^_^
@Felipecuevas
@Felipecuevas 5 лет назад
I use height: 150vw; instead of hacking the padding
@bhupinderpalsinghkaur6898
@bhupinderpalsinghkaur6898 5 лет назад
I used it in one of the projects I worked on and it worked quite well for me. I still can not properly use this bottom padding technique. Its good to know that there are other persones using the technique way as I do.
@MichaelRichins
@MichaelRichins 5 лет назад
Accessibility will fail if it's a background image and not an actual image itself.
@OfficialDevTips
@OfficialDevTips 5 лет назад
Good point! Yeah actually we had that option planned but made the video lose tempo so decided to stop having done the background-image.
@ericzorn3735
@ericzorn3735 5 лет назад
Use ref instead of directly accessing the DOM
@victorjozwicki8179
@victorjozwicki8179 5 лет назад
Inline style maybe ? reactjs.org/docs/dom-elements.html#style Pretty sure it's the right way to do it instead of selecting the dom, you should avoid manipulating the dom yourself
@fullmuppet
@fullmuppet 5 лет назад
CSS is weird.
@macaronivirus5913
@macaronivirus5913 5 лет назад
It is, but it's getting much better. Comparing possibilities and cleanliness of the code to what it had been 15 years ago, now it is the gift from heavens. Wait a bit more and it will support what scss is capable now, and that height percentage thingy too.
@shriniwasrocks
@shriniwasrocks 5 лет назад
cpu is just a rock that is fooled into thinking :D
@jobybejoy8219
@jobybejoy8219 5 лет назад
❤️
@OfficialDevTips
@OfficialDevTips 5 лет назад
❤️
@davidnagli
@davidnagli 5 лет назад
Unmm Suspense...
@joaoluiz8973
@joaoluiz8973 5 лет назад
MPJ looks a lot like RDJ.
@fanji424
@fanji424 5 лет назад
that css hack tho
@wbaloo1
@wbaloo1 5 лет назад
I'm a css perv
@HazimFauziSsMf
@HazimFauziSsMf 5 лет назад
Wow... Helo polisss... Sum1 is hacking css... Hahaha
@ablanchi
@ablanchi 5 лет назад
is mpj dead?
@floverdevel
@floverdevel 5 лет назад
From the official doc, the padding-bottom percentage trick is not a hack. «The size of the padding as a percentage, relative to the width of the containing block. Must be nonnegative.» developer.mozilla.org/en-US/docs/Web/CSS/padding-bottom#Values
@albertkoppelmaa7178
@albertkoppelmaa7178 5 лет назад
Noooooooo! you are loading the image and once it's done loading you reload it by changing the background source (url, not the actual image data) . Onload you should have just appended the image and the wait time would have been cut in half ! You are loading it two times !!
@mohammedsalman3397
@mohammedsalman3397 5 лет назад
I love you guys, and I've been following you for years now... but these type of videos are too long, I feel like they're a waste of time! You could've showed us the 5 lines you wrote in 5 minutes with better explanation or you could've just edited the video and throw cuts here and there with a "an hour later" sign. Btw: I gave it a thumbs up, just like every other video from you guys but I'm losing interest slowly as many others. * This is meant as constructive criticism.
@CrashDSInc
@CrashDSInc 5 лет назад
Seems to me that showing the process is the whole point of the videos. If you just want a quick tutorial on lazy loading images, those can already be found.
@sagar-gavhane
@sagar-gavhane 5 лет назад
Guys, I'm a big fan of David, mpj and devtips. From last couple of months video content quality is degrading. This is negative feedback but truth is truth. I don't want to demotivate you guys. I really love your previous all videos and series. Please don't mind
@TheOlian04
@TheOlian04 5 лет назад
Sagar Gavhane no, please do mind. I totally agree. The quality has been tanking for the past maybe 5 months.
@OfficialDevTips
@OfficialDevTips 5 лет назад
Could you specify what you think qualifies as the good content?
@noidarradion7087
@noidarradion7087 5 лет назад
Video is too long
@HazimFauziSsMf
@HazimFauziSsMf 5 лет назад
But the reality this is how programmer work... Haha yeah you know
@sagar-gavhane
@sagar-gavhane 5 лет назад
Topics are not interesting and we want to learn new things. I'm following FunFunFunction from last 1.5 yrs. You can clearly monitor video views, likes and user engagement with videos. MPJ is great teacher I ever saw in my career. FunFunFunction has very good cotent of Functional programming and unit testing. I know you haven't get enough time for working on videos. Two or three videos with good quality is enough for the community.
@jiggasnap
@jiggasnap 4 года назад
Eh nothing hacky about this at all, completely consistent with how the box model works.
@hironakae
@hironakae 5 лет назад
HOOMANS
@nancymikyska2832
@nancymikyska2832 5 лет назад
guys...css is awesome lol
@WilliamBay
@WilliamBay 5 лет назад
First: This is what img src set is for. Your app or CMS just needs to store thumbnails at different sizes. And based on the viewport width of the device, it will load only the appropriate sized image. WordPress does this very well. Second: Glad JP’s learning CSS. But, I was cringing the whole time. 😂
@RoterFruchtZwerg
@RoterFruchtZwerg 5 лет назад
background-size: cover; will always keep the images aspect ratio but won't allow for solid bars on top/bottom (as 100% will) if the aspect ratio is higher than you expected. I must admit this video was no fun to watch. You weren't well prepared and it was not at all obvious what you actually wanted to do. An the result was really frustrating. Also, your usecase was an editor who uploads images. You weren't including foreign images. Why did you just assume (and never mentioned it) that you don't know the dimensions of the image? Using the dimensions would be the obvious choice if they are available on the server. By using an optimized version of the image, you actually kind of require it to be on your server anyway for processing... If you want some ideas on lazy load images, I'd recommend ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-tHJwRWrexqg.html or ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ncYQkOrKTaI.html
@deimiosxxx
@deimiosxxx 5 лет назад
Dissapointed in the CSS spec. We have calc(), var(), vw and all the nifty things yet there is no better way then the padding hack to force an aspect ratio.
@jasone9185
@jasone9185 5 лет назад
Hacks == Bad. They produce hard-to-maintain and hard-to-read code. Comments should identify a code block's intentions, not how it works as the code should be self describing. I would lean towards CSS3's calc function to set the height, or use a pre-fetch if possible.
@natqe4049
@natqe4049 5 лет назад
Everything in css is a hack
@GameOver7853
@GameOver7853 5 лет назад
Very true
@eugeniomonforte6366
@eugeniomonforte6366 5 лет назад
Please, learn CSS zendev.com/ultimate-guide-to-learning-css.html
@0-Will-0
@0-Will-0 5 лет назад
I've got to say I'm pretty disappointed in this video. Sure it was entertaining, sure I learnt something. But I mainly come here to admire MPJ's hair and was let down. More seriously, for me, I'd always want the image size stored in the db. Then no hack needed. Not sure about SVG creation, so might look at a small thumbnail, which may already be in cache and a blur filter on it. Also, thumbor rules for image resizing!
@craigfreeman8225
@craigfreeman8225 5 лет назад
Here's the thing though, going to the dB and bringing that back is an async action. If you wait for that not only is it more server load but also either have to decide to not route to the page in a spa, or add extra latency for no real reason in a ssr app.
@librev5881
@librev5881 5 лет назад
First
@hamadyalghanim
@hamadyalghanim 5 лет назад
Wouldn't 150vw work?
@ArthurvanAcker
@ArthurvanAcker 5 лет назад
That wouldn't work, because you don't want 150% of the viewport width, you want 150% of the parent container
@Dylanm94
@Dylanm94 5 лет назад
He's right though. CSS sucks.
@rezamahmoudi
@rezamahmoudi 5 лет назад
This is the worst solution :)) omg! Just use data attr on one img tag and use state.
@HSMAdvisor
@HSMAdvisor 5 лет назад
I have to say I could not finish watching the last couple of videos. When two of you try to do something, it looks very raw, unrehearsed, and to be frankly UNPREPARED. Your back and forward is distracting, confusing and infuriating.
@GifCoDigital
@GifCoDigital 5 лет назад
The back and forth is the POINT of these videos. You dont like it go else where.
@HSMAdvisor
@HSMAdvisor 5 лет назад
@@GifCoDigital I fail to see the POINT. Just like the point of an argument is NOT to win, but to find a solution, the point of an educational video is to drive the POINT. Not to show a complex dynamic of two people finding a solution to something. And you are having unproductive stance on it. If everybody doesn't like the new format and just leaves, the creator will not know what he did wrong. Cheers.
@GifCoDigital
@GifCoDigital 5 лет назад
HSMAdvisor - well no one is leaving except you! Sooooo good bye and good riddance.
@HSMAdvisor
@HSMAdvisor 5 лет назад
@@GifCoDigital Good sport.
@GifCoDigital
@GifCoDigital 5 лет назад
@HSMAdvisor - its ok the anger usually fades after puberty. Good luck till then.
@tenminutetokyo2643
@tenminutetokyo2643 5 лет назад
The web is crap.
@JonPreece
@JonPreece 5 лет назад
Good idea, poor execution, unplanned, unrehearsed, difficult to watch. I'll never unsubscribe because I know you'll turn it around eventually.
Далее
Critical CSS + Fail 🧨
35:37
Просмотров 14 тыс.
Trying Docker for the First Time 📖 Many Learnings!
50:42
Ummmm We "HAIR" You!
00:59
Просмотров 13 млн
▼ЧЁРНАЯ МАГИЯ 🔮
31:15
Просмотров 265 тыс.
What is THIS in JavaScript?
33:14
Просмотров 84 тыс.
How to Load Web Fonts in 2019 🎆
21:05
Просмотров 20 тыс.
Creating A React Component WITHOUT React
49:51
Просмотров 8 тыс.
How to Do 90% of What Plugins Do (With Just Vim)
1:14:03
Просмотров 870 тыс.
CSS - Курс по CSS для Начинающих
1:27:35
Query Parameters in JavaScript (3+1 Ways)
17:18
Просмотров 19 тыс.
Create a CSS only lightbox using :target
34:08
Просмотров 68 тыс.