Nginx PageSpeed rewrite_images and webp automatic conversion

Centmin Mod based Nginx server has Nginx PageSpeed module integrated. By default, Centmin Mod Nginx PageSpeed disables the PageSpeed rewrite_images filter to lower the incurred server resource overhead that Nginx PageSpeed has when enabled.

For the purpose of testing, I decided to re-enable the Nginx PageSpeed rewrite_images filter along with a few other image optimisation related filters including automatic conversion of images to new Google webp format if the image is deemed to benefit from the conversion.

Nginx PageSpeed will:

  • Automatically calculate if there is any benefit in terms of image file size. If there is no benefit, Nginx PageSpeed will not convert to webp format.
  • Only serve the rewritten webp format image to browsers which support webp. Non supported browsers will get the original image instead.

The following are the relevant Nginx PageSpeed filters I enabled via pscontrol edit shortcut command. To properly load all the below images, you’d have to scroll down as I have the Nginx PageSpeed filter, lazyload enabled.

pagespeed EnableFilters rewrite_images;
# pagespeed DisableFilters rewrite_images;
# pagespeed DisableFilters recompress_images;
# pagespeed DisableFilters convert_png_to_jpeg;
# pagespeed DisableFilters extend_cache_images;
pagespeed EnableFilters convert_png_to_jpeg;
pagespeed EnableFilters convert_jpeg_to_webp;
pagespeed EnableFilters convert_to_webp_lossless;

Below are some test jpg images and will see how well the re-enabled Nginx PageSpeed rewrite_images filters do.

Checking Nginx PageSpeed message log I can see successful automatic conversion of the above jpg images to Google webp format. With quite a substantial amount of savings in terms of image size !

[Info] [14346] https://../121:105: Shrinking image `https://../../Intel-Xeon-Processors.jpg' (54675 bytes) to `https://../../620x298xIntel-Xeon-Processors.jpg.pagespeed.ic.LDGeebUM0O.webp' (25200 bytes)
[Info] [14346] https://../121:106: Shrinking image `https://../../Intel-Xeon-Server-Roadmap-635x394.jpg' (74654 bytes) to `https://../../635x394xIntel-Xeon-Server-Roadmap-635x394.jpg.pagespeed.ic.w_1wjxFvpy.webp' (38202 bytes)
[Sat Aug 17 10:34:34 2013] [Info] [14346] https://../121:107: Shrinking image `https://../../image_000.jpg' (137512 bytes) to `https://../../675x900ximage_000.jpg.pagespeed.ic.7f_rsR8poY.webp' (54662 bytes)
[Sat Aug 17 10:34:34 2013] [Info] [14346] https://../121:108: Shrinking image `https://../../image_001.jpg' (185875 bytes) to `https://../../900x600ximage_001.jpg.pagespeed.ic.CNIawxykO6.webp' (98500 bytes)
[Sat Aug 17 10:34:34 2013] [Info] [14346] https://../121:109: Shrinking image `https://../../image_003.jpg' (176753 bytes) to `https://../../900x675ximage_003.jpg.pagespeed.ic.8FdFT9sV1k.webp' (97832 bytes)
[Sat Aug 17 10:34:34 2013] [Info] [14346] https://../121:110: Shrinking image `https://../../image_004.jpg' (154625 bytes) to `https://../../900x675ximage_004.jpg.pagespeed.ic.78qk84BaLO.webp' (71056 bytes)

If you check Nginx PageSpeed statistics, it reconfirms the savings and number of image rewrites performed by Nginx PageSpeed. This blog has other jpg images within css files that also got rewritten to Google webp format as well. Approximately 51% reduction in image sizes with Nginx PageSpeed enabled. These savings are not just from webp conversion, but include other automatic image optimisations done to all images hosted on the server. Such as the recompress_image filter.

image_file_count_reduction: 0
image_rewrites: 15
image_resized_using_rendered_dimensions: 0
image_norewrites_high_resolution: 0
image_rewrites_dropped_intentionally: 0
image_rewrites_dropped_decode_failure: 0
image_rewrites_dropped_mime_type_unknown: 0
image_rewrites_dropped_server_write_fail: 0
image_rewrites_dropped_nosaving_resize: 0
image_rewrites_dropped_nosaving_noresize: 0
image_rewrites_dropped_due_to_load: 0
image_rewrites_squashing_for_mobile_screen: 0
image_rewrite_total_bytes_saved: 405101
image_rewrite_total_original_bytes: 798989
image_rewrite_uses: 25
image_inline: 0
image_webp_rewrites: 15
image_ongoing_rewrites: 0
image_webp_conversion_gif_timeouts: 0
image_webp_conversion_png_timeouts: 0
image_webp_conversion_jpeg_timeouts: 0
image_webp_alpha_timeouts: 0
image_webp_opaque_timeouts: 0


Posted in Centmin Mod, Google PageSpeed Tagged with: , , , , , , , , , , , ,
× -