• This is stressing me out.. as the SRC set in wordpress often does!

    I have set my image sizes to not hard crop. In generateblocks, the images are set to be ‘medium’ size, and browser testing shows that this is what is being rendered, i.e. 400px wide.

    However, any testing in pagespeed ALWAYS shows the medium-large size is being rendered at 768x 511 px. this is not what any browser shows me…

    result here: https://pagespeed.web.dev/analysis/https-vepfinance-dreamhosters-com/xcgsje3tso?form_factor=mobile

    i am totally at a loss. the only way to make this work as expected is to disable the image SRC set using

    add_filter( ‘wp_calculate_image_srcset’, ‘__return_false’ );

    which obviously is not ideal.

    Why is this happening? can you please assist as its driving me mad. I have tired adding in filters to modify the sizes output but this has no effect.

    Thank you!

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • ying

    (@yingscarlett)

    Hi there,

    Are you referring to the background image of the hero section?

    If so, it doesn’t seem to be set to medium size, can you show me a screenshot of the background image setting in the GB container?

    Thread Starter capitalismclown

    (@capitalismclown)

    hi,

    no, if you look at the page speed report it is the logo in the hero section, and the two images below that.

    they are definitely set to medium and render as medium in all browsers I’ve tested.

    but page speed / lighthouse always shows the warning to properly size images, which it’s saying is the medium large size. I’m lost!

    j

    ying

    (@yingscarlett)

    High resolution screens of moder mobile devices requests image with 2x resolution, which means, a 350px width mobile device requests images with 700px width image.

    So the 3 images are loading the 768px version on mobile, the report is correct.

    Try using this PHP snippet to ask the browser to load 300px width images on mobile:


    function db_modify_srcset_sizes($sizes, $size) {
    $sizes = '(max-width: 500px) 150px, (min-width: 501px) 300px, (min-width: 769px) 1024px, 100vw';
    return $sizes;
    }
    add_filter('wp_calculate_image_sizes', 'db_modify_srcset_sizes', 10 , 2);
    Thread Starter capitalismclown

    (@capitalismclown)

    HI, this seems to have worked, thank you!

    I do understand about retina screens, but I have been following google’s own guidelines on this. I guess it is somehwat misleading then? or is my information out of date? I usually test at 480px wide for mobile (or smaller). realistically then, I should be testing the page at arouns 800px wide?

    there are a lot of conflicting answers about this. its hard to know exactly what I should set to satisfy pagespeed / core web vitals, if im having to alter the SRC set each time to be half of what it actually is. madness really.

    ying

    (@yingscarlett)

    Just remember that mobile devices actually requests 2 x resolution images.

    In my code, I asked the browser to load 150px images on screens that are narrower than 500px, so on the actual mobile device, the 300px width image will be loaded.

    Thread Starter capitalismclown

    (@capitalismclown)

    i see well that makes sense.

    either way your filter does a good job. I’ll keep that handy. Obviously at larger sizes I can adjust the slot size as needed. I do understand the code, how it works with src set and page speed insights in the real world is another thing entirely.

    on other site builds in fact I don’t use the sizes parameter and set custom image sizes instead and use those, setting each one for specific widths as the default wordpress is so out of touch with reality. This build is a bit too simple for such work, however, so this solution is perfect, thanks again.

    j

    ying

    (@yingscarlett)

    You are welcome   🙂

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Pagespeed always returns medium-large image’ is closed to new replies.