Using this tool you can optimize your media directly in Shopware to save disk size and traffic to optimize the load of your page, which also optimizes your google pagespeed rank.
Keep in mind: The optimisation of your media files is made lossless, your files will not be compressed. The optimisation only strips meta data and for displaying unnecessary data to shrink the filesize! To compress the files, you should still use the shopware internal compression.
Apparent from our tests, another compression by these tools won't shrink your files again, so it's enough to compress them by using the Shopware settings and just let the tools optimize the files lossless.
While uploading new files using the media manager, the optimizer automatically generates optimized thumbnails of your media. The original will remain unaffected.
This way we make sure, that you are able to generate new thumbnails from your media using the real original.
When you've e.g. updated Shopware and you already have your system running, you can regenerate all your thumbnails. At regenerating all thumbnails, those files will also processed by the optimizer, the original will remain unaffected here as well!
To optimize your media manually, you need to open an ssh session, navigate in the Shopware root directory and execute the following command to start optimizing:
bin/console sw:media:optimize [parameter] [path]
Shopware now scans your file system for media and optimize them.
Keep in mind: This command will check the whole Shopware installation for media files and optimizes them by default. If you have other non-Shopware media files, this command will optimize them too! So if you want to optimize only your Shopware media files, make sure to add the path to your command to optimize just the files in this desired directory.
Here we have a few examples:
// Help bin/console sw:media:optimize -h // Info about the optimization tools bin/console sw:media:optimize -i // Optimize media files just in this folder bin/console sw:media:optimize /var/www/media // Limit the files to gather by date/time bin/console sw:media:optimize -m // Verbose bin/console sw:media:optimize -v
Shopware can use the following tools by default:
If at least one of these tools is installed, the supported MIME-types will be optimized over this tool. If more tools are installed, an internal logic will ensure, that only the better tools is used for optimizing your media files. If no tool is installed, the process will finish without any optimization.
Please ask your hoster about these tools and let him install at least one per used MIME-type, we suggest jpegtran & optipng.
With the modified parameter your can limit the selection by using e.g. the following examples:
// Only optimize media files of the last 7 days bin/console sw:media:optimize -m="after 7 days ago" // Only optimize media files of the last 2 weeks bin/console sw:media:optimize -m="after 2 weeks ago" // Only optimize media files of all media since the last month bin/console sw:media:optimize -m="before 1 month ago" // Only optimize media files befire last tuesday bin/console sw:media:optimize -m="before last tuesday" // Only optimize media files before 4 am this day bin/console sw:media:optimize -m="before 4 am ago" // Only optimize media files before 2017/01/01 bin/console sw:media:optimize -m="before 2017/01/01"
Notice: The "modified" parameter is php, so it's relative to the current moment and its php syntax. For this reason, we link to the php documentation: php datetime formate, you can use all the functions listed there.