---
title: "Adventures in making this website:
image optimization"
date: 2023-02-27
layout: "blog"
toc: true
---
Published on 2023-02-27.
Making and managing this personal website has been an adventure.
In this series, I go over the technical challenges I've encountered
and philosophical decisions I've made,
and I review some of the tools I've used along the way.
After [part 1](/blog/2022/website-adventures-generators/),
[part 2](/blog/2022/website-adventures-basics/)
and [part 3](/blog/2022/website-adventures-maths/),
this is part 4.
## Principles
After some consideration,
I settled on the following five commandments of image optimization
for this website:
1. **Provide the originals.**
If any scaling or lossy compression has been done
on an image displayed on the page,
wrap it in `` linking to the full-size lossless original file.
2. **Prioritize quality**.
My server provider doesn't charge me for traffic,
and there aren't many images on this website,
so I can afford to keep the quality high.
The degradation of an 80% JPEG compared to 90%
isn't worth it just to save a few kilobytes.
You should do your own tests to decide what quality
is acceptable for the kind of images you have.
3. **Limit the resolutions.**
It's wasteful to use a 2000px wide image
if it's only 200px wide on a user's screen.
I use the following rules to choose resolutions:
1. If an image is `W`px wide my screen,
its resolution should be roughly `1.5*W`px:
a 50% surplus is friendly to high-DPI screens,
and prevents scaling artefacts.
This rule also works in reverse:
if I have an `X`px file for whatever reason,
its scale should be chosen such that it takes up around `0.67*X`px on my screen.
2. Because my website's `` is ~720px wide for me,
the largest sensible image width is ~1080px.
But sometimes more is needed to show all details:
in that case, display a downscaled image on the page,
linking to the original.
When downscaling, always divide the width and height
by an integer divisor of both.
4. **Use modern formats.**
The JPEG standard was released in 1992,
and in the three decades since then,
a lot of research has been done in image and video compression.
If a modern format can shrink files by 75%
with little to no change in quality, why wouldn't I use it?
5. **Maintain compatibility.**
Modern image formats are great, but some are so modern
that almost nobody can use them, so fallbacks should be provided.
Fortunately, HTML has a built-in way to do this, see below.
The HTML `