[{"_path":"/blog","_draft":false,"_partial":false,"_empty":false,"title":"Blog","description":"","excerpt":{"type":"root","children":[{"type":"element","tag":"jumbotron","props":{},"children":[{"type":"element","tag":"template","props":{"v-slot:highlight":""},"children":[{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Check out"}]}]},{"type":"element","tag":"template","props":{"v-slot:title":""},"children":[{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Dev Blog"}]}]},{"type":"element","tag":"template","props":{"v-slot:perex":""},"children":[{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"I believe in learning in public. I share my "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"know-how, practices, and workflows"}]},{"type":"text","value":". If you have questions or comments about any of the articles hit me up on "},{"type":"element","tag":"a","props":{"href":"https://twitter.com/maceksimondev","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"Twitter"}]},{"type":"text","value":"."}]}]}]},{"type":"element","tag":"article-list","props":{},"children":[{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Newest posts"}]}]}]},"head":{"title":"Blog","description":"Regular snippets of developer know-how."},"navTitle":"Blog","hideBreadcrumb":true,"_type":"markdown","_id":"content:4.blog.md","_source":"content","_file":"4.blog.md","_extension":"md"},{"_path":"/blog/5-tools-for-image-optimization","_draft":false,"_partial":false,"_empty":false,"title":"5 Tools for Image Optimization","description":"Image optimization can be the thing that makes or breaks your performance scores. Here are some of the popular tools that help you to deal with large images.","excerpt":{"type":"root","children":[{"type":"element","tag":"h1","props":{"id":"5-tools-for-image-optimization"},"children":[{"type":"text","value":"5 Tools for Image Optimization"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Image optimization can be the thing that makes or breaks your performance scores. Here are some of the popular tools that help you to deal with large images."}]},{"type":"element","tag":"h2","props":{"id":"key-concepts-of-image-optimization"},"children":[{"type":"text","value":"Key concepts of image optimization"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Images such as a photographies, info-graphics, or illustrations are made of pixels. The more pixels you have, the more detailed and larger the image is. Modern DSLR cameras can easily spit out images with width and height over 3000px. This can mean 4-5Mb of data which is far to much for images to load smoothly."}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"The problem gets worse when you switch to "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"mobile devices"}]},{"type":"text","value":". Many internet users have a limited data plan, and downloading a bunch of large images can drain it in no time."}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Moreover, loading images usually makes up for a large part of the website's performance issues. Since the performance recently became a "},{"type":"element","tag":"a","props":{"href":"https://developers.google.com/search/blog/2010/04/using-site-speed-in-web-search-ranking","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"factor in SEO ranking"}]},{"type":"text","value":". Large images may "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"hurt your position on Google results page"}]},{"type":"text","value":"!"}]},{"type":"element","tag":"h3","props":{"id":"image-resolution"},"children":[{"type":"text","value":"Image Resolution"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"You should "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"scale down"}]},{"type":"text","value":" your images from its source resolution. What resolution do you need?"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Imagine a large computer screen. Those typically have Full HD resolution: 1920x1080 pixels. Image with higher resolution will only get scaled down to fit your display and the extra data will get lost."}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"If your image does not take the full width of the screen, you need even less pixels. Most of the images used on websites are relatively small. For a blog post, I typically use about "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"600-800px"}]},{"type":"text","value":" wide images, and they look great."}]},{"type":"element","tag":"h3","props":{"id":"image-compression"},"children":[{"type":"text","value":"Image Compression"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Another important step aside from resizing is the image compression. Compressing the image results in lower quality, but it can make the file size much smaller. Content creators are often afraid of compression and claim that their images do not look as good compressed. But with the right tools, you can achieve "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"compression that is virtually indistinguishable"}]},{"type":"text","value":" from the original."}]},{"type":"element","tag":"h3","props":{"id":"image-format"},"children":[{"type":"text","value":"Image Format"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Sometimes the image format can also play a role. Importantly, the recently introduced .webp format created by Google is extremely efficient in producing high-quality images with a small file size. The catch is that not all browsers support this format. I will get to how to solve this issue later."}]},{"type":"element","tag":"h2","props":{"id":"optimization-tools"},"children":[{"type":"text","value":"Optimization tools"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Here are some great tools which I use regularly to optimize my images."}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"a","props":{"href":"https://bulkresizephotos.com/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"BulkResizePhotos.com"}]},{"type":"text","value":" is a flexible tool that allows you to scale large batches of images to a desired width or height. It outputs .jpg, .png or .webp files."}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"a","props":{"href":"https://tinypng.com/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"TinyPNG.com"}]},{"type":"text","value":" is an amazing compression tool, which can compress images by a considerable amount while keeping their resolution."}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"a","props":{"href":"https://cloudinary.com/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"Cloudinary"}]},{"type":"text","value":" a full-featured service for hosting, optimizing and serving images which can be integrated to any website and can save a lot of manual work."}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"a","props":{"href":"https://imageoptim.com/mac","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"ImageOptim"}]},{"type":"text","value":" is tool for iOS which allows to compress images right inside your computer. Just right click and select 'ImageOptimize', and watch the app save you space."}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"a","props":{"href":"https://jakearchibald.github.io/svgomg/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"SVGOMG"}]},{"type":"text","value":" - this one optimizes SVG graphics. SVGs are a topic on its own, so I will probably write about them soon."}]}]},{"type":"element","tag":"h2","props":{"id":"using-the-tools"},"children":[{"type":"text","value":"Using the tools"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"As you can see, there are multiple tools that help with image optimization. But how to use them? One option is to use BulkResizePhotos and TinyPNG to optimize your images before the upload. This is an ideal solution for saving space on your hosting platform. It does, however, introduce those few extra steps into the content editing."}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Instead, we could use something like Cloudinary, to make this process automatic. "},{"type":"element","tag":"a","props":{"href":"https://cloudinary.com/documentation/wordpress_integration","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"Cloudinary's WordPress plugin"}]},{"type":"text","value":" does just that. It loads images from your media library and serves them to your website from its own CDN. This ensures that you load an optimized version of the file every time, and it even "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"fetches the correct format"}]},{"type":"text","value":" for you!"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Each content management system has developed at least some way of controlling the image sizes. Custom implementations can be made (on my WordPress sites, I tend to use a custom automated solution designed by one of my colleagues - with their consent). But the key takeaway is that "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"image size matters"}]},{"type":"text","value":"."}]},{"type":"element","tag":"h3","props":{"id":"images-in-code"},"children":[{"type":"text","value":"Images in code"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"For a little preview of what goes into image optimization, here are some code snippets."}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"This is a basic image tag that displays an image in a HTML page."}]},{"type":"element","tag":"code","props":{"code":"\n","language":"html"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"Example image","src":"https://res.cloudinary.com/pavilionpreview/image/upload/v1654713084/sample.jpg"},"children":[]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"The simplest thing that can be done to improve loading your page is adding the "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"lazy loading attribute"}]},{"type":"text","value":". This means that the image will not load until the user scrolls down to it."}]},{"type":"element","tag":"code","props":{"code":"\n","language":"html"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Additionally, we can add images in different formats using the "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"