There are many tools to optimize images, and it is hard to remember how to use them correctly.

I have recently found imagemin and I have been only using this tool ever since. It is an open source JavaScript module made by the one and only sindresorhus (a prolific open source dev).

👩‍💻 How to optimize images

Start by making sure you have installed Node.js and NPM, because the tool we are using is written in JavaScript.

Then you can use npx imagemin-cli input.png > output.png to optimize input.png and save it as output.png.

This tool supports jpeg, webp and png images, so you have no excuse not to optimize all of your images before publishing them on the web!

One more trick: if you're using this tool often, install it globally using npm install --global imagemin-cli so that you don't wait for npx to query NPM.