Image compression has to be managed through these steps:
- WebP Express plugin has to be installed and configured based on the website requirements. All assets are to be delivered through WebP format
- You can either use functions.php or Easy Image Sizes plugin to add other sizes (more on Image Sizes thread) as required.
- All theme implementation of images and assets must refer to WordPress’ media library and called through wp_get_attachment image and wp_get_attachment_image_srcset as described here.
- Image sizes must be explicitly declared within the image tag
- I would suggest to always ask for the biggest image available and let srcset handle the image sizing optimization.
- You can check correct implementation of these parameters in the above examples of feature image and post media image.
An example of correct feature image and post image with srcset attributes can be found here