How to apply Image Style with no effects and lazy load image? We have two content types (Articles and Basic Page) that use the same Image (field_image) field. We are using the lazysizes js library where you need to add class="lazyload" and data-src="image-url.png" on the &lt;img&gt; tag. 

For the Article Content type only we want to be able to lazyload the images, but we want to do in a way that does not impact the Image field on the Basic Page content type. 

We initially thought that the best way to do this was to assign an Image Style with no effects and then use the mytheme_preprocess_image hook to do the following below. 

Is this the correct way to modify the &lt;img&gt; element the way we need to? The goal is to be able to lazyload the original image without modifying it (no scalling, resizing, cropping, etc.). 

function mytheme_preprocess_image(&amp;$vars) {
  $lazy_loading = [
    'lazy_load_image_style' // Machine name of Image Style.
  ];

  if(in_array($vars['style_name'], $lazy_loading) {
    // Copy src into data-src.
    $vars['attributes']['data-src'] = $vars['attributes']['src'];
    unset($vars['attributes']['src'];

   // Add css class.
   $variables['attributes']['class'] = 'lazyload';
}
It may be easiest to use Blazy or Image Lazyloader.

If neither of those suit your needs, I would create a new field formatter class. In your custom module create a new formatter src/Plugin/Field/FieldFormatter/LazyImageFormatter.php that extends Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter.php. 
 You'll need to use the same annotation that formatter has, but then you'll only need to implement the viewElements method. Begin the method by calling $elements = parent::viewElements($items, $langcode);. Traverse $elements afterward and update the render array similar to how you have done above. Make sure to return $elements; when you're done.

This will give you a formatter on the manage display screens that you can select on whichever image fields you want on any view mode of any entity. You can even get it to work with any image style selected via your new formatter. 

If you've never extended a Drupal 8 plugin check out the plugin api. Once you know how to create and extend one plugin type it's very similar process to create or extend others and you'll quickly find that the world is yours.