Optimization for the Web
A loose benchmark web developers are aiming for when looking at page size is 1MB – 2MB. Pages that meet this benchmark will generally download in under 2 seconds, which is important because people begin to bounce from a page that has not loaded after 2 seconds, and every second after that the number of people who leave increases exponentially. So to avoid people leaving without seeing the content, it needs to load in under 2 seconds.
Every image that goes onto a website should be optimized. Unfortunately, this can mean drastically different things for different images. The first step to optimizing an image is choosing the right file type. Image optimization is a design consideration, and images should be optimized before they reach the web developer.
Image File Types
- JPG: are the most common image format, and are the best choice for larger images with lots of colors. They support lossy and lossless optimization, and each JPG should be reduced in size until the optimization becomes noticable in the quality of the image. For some images this means reducing them to 90%, for others it could mean taking them down to 15%.
- PNG: are traditionally lossless, however there are now programs that will optimize a png, some in a lossy way and others in a lossless way. In general, you only want to use PNGs over a JPG if the background of the image needs to be transparent, or for small images with limited colors (they produce smaller file sizes for small simple images).
- GIF: are large and lossless. They should be used only when you need an animated image.
- SVG: are the best choice if the image was created by vectors. They are most commonly used as icons, and they will typically produce the smallest and fastest files. They are a lossless format that can scale infinetly on the web while remaining crisp. They can also be animated on the web via CSS and JS, making them a versatile and excellent choice when appropriate.
If you are using a JPG, the next thing you need to do is find the correct optimization level. Every image is different, so for the best results don’t just save every JPG at 60% compression. Look at what happens to the image at different levels of compression, and decide which one works best.
Optimization Examples
JPG – 590 KB – Image looks great, but its too large. 590KB is ~25% of 2MB, too much for one image to take up.