Shopware Media Optimizer

Gültig ab Version:
5.2.17

Introduction

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.

Caution! The provided informations were tested at the release of this article, but can be change during the releases of Shopware. The application of this tutorial appears on your own risk! Make a Backup of your shop before your start that you have a backup in case of failure. Keep in mind, that this is adapting Shopware an this is not officially supported!

Procedure

At uploading new images

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.

Update of existing media files without ssh

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!

Manually optimization via Shell

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
 

The different optimizers

Shopware can use the following tools by default:

Programm Supported MIME-Types
jpegoptim image/jpeg, image/jpg
pngout image/png
optipng image/png
jpegtran image/jpeg, image/jpg
pngcrush image/png

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.

The modified parameter

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.

Extend the optimizer

The media optimizer can be extended using plugins to include more tools or setup the existing tools more individual. If you need such an extension, please take a look at our developer documentation for the media optimizer.

Weitere interessante Artikel:

Debugging in Shopware

Debugging of errors, wich won't appear in the logfile module Shopware uses multiple Frameworks and tools and so it might happen, that you see errors, which don't appear in the logfile module, because they won't appear in the backend e.g....

weiterlesen

FAQ: Error messages and their causes

Introduction In this article you'll find common error messages and their possible causes. In much cases you may get an easy solution approach. Error messages in Shopware will not automatically shown in the frontend to provide a better customer...

weiterlesen

Performance tips Shopware

Performance tips Shopware General tips and tricks {| |- ! subject !! standard !! optimum !! info |- | PHP version || - || 7.0.x || PHP 7.0.x, depending on the circumstances, this version offers a possible performance increase of up...

weiterlesen
€ 10,00

Preise inkl. gesetzlicher
MwSt. + Versandkosten*