-
-
Notifications
You must be signed in to change notification settings - Fork 28
Provide recommended widths for 'srcset' images #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Do you know a best practise threshold for these kind of calculations? Something like 250.000 square-pixels?
Or maybe something larger like 500.000 square-pixels? |
I don't — trying to figure that out now 😊 Cloudinary has a tool for it but, annoyingly, they put their algorithm on the server instead of client-side. I suppose someone could reverse-engineer it if they thought about it long enough. I created an issue in Google Lighthouse too, so maybe they'll have some opinion/perspective: GoogleChrome/lighthouse#13563 |
Here are some more links on the topic:
|
Couple of questions I'm uncertain about:
|
In re-reading the thread on GoogleChrome/lighthouse#11593 (comment), it seems like the best solution would be to:
A function like |
Added a recommentation in 35df131 Looks something like this now: |
It looks like WordPress uses 2048 as the upper bound for an image used in I had previously mentioned 1920 as a default upper bound but it probably makes sense to simply match WordPress. The default recommended widths probably should be between 150 and 2048. What do you think? |
I set the upper bound to 2048 and the lower bound to 256 in 6317042 |
The lower bound is now more “flexible” meaning the recommended size can get lower if the max size is lower or if it detected a fixed (non-fluid) size that is smaller. @danielbachhuber Can you please retry your avatar example? |
Great work! The results for the avatar example seem more sensible now: When I add The live URL is https://www.foodbloggerpro.com/ if you want to try it out. Here's another edge case I found that we could potentially track as a separate issue: I'm not sure the 268w recommendation makes sense for that image, given it won't display until 768px width (768 * .465 = 357.12). Any ideas what's going on there? Also, what do you think about rounding the suggestions to the closest 10 (e.g. 268 -> 270)? I feel like it might be a little more human-friendly. Lastly, for the sake of the next person to come across this thread, could you s 8000 hare a high-level summary of how the code...
|
Found another one 🙃 On our membership page, Lighthouse is flagging an image that the bookmarklet identifies as passed: The image's markup is:
There's also an odd recommendation with this one:
|
The first The other errors are due to the fact that the check-algorithm doesn’t use the same threshold (in megapixels) as the algorithm that calculates the recommendation. I have to update the check-algorithm and then these errors should go away. |
Ah, good catch. It doesn't seem like |
To recap some of our conversation on Twitter (which I think will be helpful for historical context): D: Still getting marked as passed… D: Does it show up as passed for you? foodbloggerpro.com/membership/ M: the current setting of the linter is set to allow a distance of 0.75 megapixels that seems to be too large for google... D: Here’s the source code for the Google check https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/audits/byte-efficiency/uses-responsive-images.js M: yes, it calculates the diffrence in bytes which we cannot do :/ D: I think this is where we could be running into GoogleChrome/lighthouse#11593 and ultimately the suggestion of GoogleChrome/lighthouse#11593 (comment) M: I’d have to lower the threshold to 0.35MP for the image #2 to fail, so I think google is too strict there indeed D: A couple of options I see:
If you didn’t feel like 1 was too much of a hack, we could always start with 1 and then do 2. M: hard coding image sizes to a specific device would not be a long term solution as I would guess that google updates such things regularly... D: Well, I think that Google would change it to an algorithm that isn’t restricted to device size, and when it’s applied it will be noted on that issue. The current restriction hasn’t change for two years. D: Ultimately, the challenge is that most people using the bookmarklet will want the bookmarklet to solve for the warning in Google Lighthouse. It may be a scenario where the “optimal for the real world” solution is different than the “technically optimal” solution. M: I agree that it should make google lighthouse happy for most cases. D: Oh, good point. We use Cloudflare to dynamically serve PNG as WebP, but it only kicks in after the image is in cache (i.e. not very reliably). M: lighthouse also suggested using webp for your website, but I cannot reproduce that now. the results are always slightly different... :/ D: Yeah, once Cloudflare kicks in, the WebP suggestion goes away. The specific example is now fixed! For this particular issue, I think it'd still be helpful to:
The |
Sure! When the linter runs, it resizes the viewport (browser window) to many different dimensions and checks how large each image is for each viewport. The Next, it adds the lowest and largest measured size of the image to the recommendation list too. From this list it then removes sizes that are less than 0.2 megapixels apart. At the end of all of this we get a list of image widths where every gap between them is from 0.2 to 0.75 megapixel large. And for the non-fluid sized parts of an image we have an exact match for @1x and @2x screen resolutions. |
💯 Nice work on this! |
Thanks for the awesome bookmarket! It's very good 😊
Most of my work is with WordPress, which offers some standard but generally incorrect
sizes
attributes out of the box, so this bookmarklet is very helpful for figuring out what the expectedsizes
attribute should be.WordPress also generates a variety of image sizes out of the box, but they may or may not be sufficient for
srcset
. An awesome enhancement to this bookmarklet would be to provide recommended widths forsrcset
images.This is probably the preferred approach: GoogleChrome/lighthouse#11593 (comment)
The text was updated successfully, but these errors were encountered: