WebP is an image format that provides superior lossless and lossy compression, animation and alpha transparency developed by Google in 2010. By using WebP developers can gain better-compressed images than JPG or PNG, in turn, providing better overall performance on the web.
While support for handling WebP has been slow, in recent years there has been a significant uptick in support for WebP, both in modern web browsers, front-end build tools, and hosting providers.
Acquia took notice, and took customer's requests for WebP support to heart, and I'm delighted to share that the Acquia Cloud Platform now supports WebP — albeit with a required additional code snippet that you will need to add to your application's codebase.
Out-of-the-box, Acquia supports PHP's native GD image processing library for converting and optimizing images uploaded via Drupal. In this workflow, Drupal's image processing toolkit uses PHP's built-in GD2 image manipulation toolkit, and images are processed within the same PHP request that handles the file upload and/or when image styles are generated. Depending on the level of image processing, this can tie up a PHP proc for a second or more. While this approach is sufficient for small-to-medium traffic sites, it's not ideal for high traffic websites that require as many free PHP procs available as possible to handle incoming requests.
As a best practice we recommend offloading image processing from PHP to the ImageMagick convert binary that is installed on all Acquia servers. This frees up PHP procs to handle incoming requests while ImageMagick processes your images as a background server task. While the ImageMagick library and binary is pre-installed, you will however need to add the ImageMagick module to your codebase and enable it. You will also need to change your application's image toolkit from GD to ImageMagick as defined within your Drupal admin dashboard at
Fellow Acquian Alex Moreno Lopez has an excellent and detailed write-up of setting up ImageMagick with WebP, using his WebP module within a Drupal 8 site running locally within DDEV. I highly recommend referencing his article for implementation details as well as more insight as to why WebP is such a big deal and why you should consider using it to improve your site's performance.
What about that additional code snippet?
As previously mentioned, Acquia Cloud Platform now supports WebP, but requires a minor addition to your site's .htaccess file to tell Apache and Drupal what to do with files ending with the .webp file extension.
Drupal's .htaccess file is located in your codebase's docroot. Within your .htaccess file, you will need to add the following line in order to properly set the WebP MIME type:
# Add webp MIME type so that Apache knows how to handle WebP images AddType image/webp .webp
Once your updated .htaccess file is deployed, you should then be able to view WebP files being served from Drupal, and be well on your way to improving site performance and impressing your visitors with a snappier website!