Magento 2 Page Speed Fixing Duplicate Product ImagesPage Speed

« Back to Magento 2 Page Speed

Serve resources from a consistent URL

If you've ever ran a GTMetrix speed report, one of the harder to fix recommendations it gives is the Serve resources from a consistent URL message:

Serve resources from a consistent URL

This means that you have 1 or more images that have different filenames (ie. are different images on the server) but contain the exact same content. In other words, you have uploaded the same image to different products and Magento has renamed it on each upload and now multiple copies of the image exist.

This is a bad idea because it means the customer is downloading the same image multiple times.

The Fix

Fortunately, using the Magento 2 Page Speed module this is extremely easy to do. The module provides a handy CLI command that does this for you.

bin/magento fishpig:pagespeed:duplicate-product-images

The above command will calculate how many product images you have that are duplicates in your system and will then provide options on what to do next. You have 3 options:

  • List Duplicate Images

    bin/magento fishpig:pagespeed:duplicate-product-images --list

    This lists the images and the duplicates but it does not remove them.

     

  • Clean Duplicate Images from the Database

    bin/magento fishpig:pagespeed:duplicate-product-images --clean

    This will clean the duplicate images from the database but it will NOT delete them from the server

     

  • Clean Images from the Database and Delete Images from the Server

    bin/magento fishpig:pagespeed:duplicate-product-images --clean --delete

    This will clean the duplicate images from the database and it will delete them from the server. You cannot call --delete without --clean