Blurhash: A compact representation of a placeholder for an image
github.com
github.com
Wouldn't it be possible to generate a tiny SVG or some CSS that reproduces these gradients?
In that case, basically no decoding step is needed and integration is as easy as setting a CSS style on a div or including an SVG. If the image dimensions are set from the start, the browser can even continue layouting the page before actually drawing the gradients. Letting the browser decode the gradients should also be much faster.
Is there a library that does that?
I think Blurhash is the way it is because Wolt is an app and not a website, so the decoder is already loaded when you open it. For browser use, SVG would be more straightforward.
A CSS Houdini worklet would be another way to represent this in CSS.
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Houdini
Then again, progressive JPEG or FLIF is not supported that well anywhere, so I guess this could be the best thing right now because it seems to just require HTML5 canvas.
Wonder if anyone's turned Instagram's version of Blurhash into a library?
The placeholders are blurred and I assume that creating blurred images is pretty expensive and takes O(N^2*M) where N is size of the image and M is number of points.
Wouldn't it be cheaper to use blocky placeholders that take only O(N^2) time to paint?
If you're sensible and use small input images, and therefore small hashes, it should be fine. It's not actually doing all that much 'work'. Besides, browsers are much faster than people think they are, especially for things like canvas drawing because that happens on the GPU (even in a 2d context.)
I assume that creating blurred images is pretty expensive.
The input image is converted to a hash. When the placeholder is needed the hash is converted to a gradient. Essentially it's like picking a few points in an image and then using a gradient function to fill in the spaces between the points. That's something that's easy for a computer for do quickly.
Also, as it happens, blurring an image is fast too. You can implement a Gaussian blur in a convolution filter, and that's just a simple matrix.
Does "people" include you?
Also web pages are more bloated than people think they are.
Without wishing to create a paradox, it absolutely does, yes. I've been a web dev since 1997 and I frequently have to remind myself that I don't always need to optimize things, memoize things, or throw features out based on browser performance any more. I constantly underestimate what browsers are capable of. There's a 'pandemic' of over-optimization that heaps complexity (aka bloat) into web apps unnecessarily based on the mostly wrong belief that browsers are slow.
Devs need to be careful, and they need to measure things. They shouldn't start with the assumption that something will be slow.
What's really interesting about this whole question is that HN's least favorite frontend library, React, suffers this problem. The virtual DOM implementation was necessary a decade ago when React started, but DOM manipulation has been optimized in browsers so now the vdom is actually a bit of a hinderance (React has advantages other than speed, so it's still a fine choice.) Libraries that HN likes, such as Svelte and Solid, rely on the browser to be fast, because the browser is fast.
I disagree. The specs of developers' machines typically so far surpass those of users as to make that assumption valid more often than not.
Further, the fail case for incorrectly assuming that a web page will be fast ranges from it being slow to it being unusable, while the fail case for incorrectly assuming that a web page will be slow is that it is slightly more responsive than expected.
Billions of people are using computers that are 100 times slower than your machine in different metrics. 100 times less space on hard drive, 100 times slower hard drive, 100 times slower processor, 8-16 times less memory, etc.
But then they probably won't pay you anyway, also if you target them, you have to make compromises that will affect the overall quality.
I wish we lived in a pandemic of over-optimization.
Serious question: my 2017 MacBook Air grinds to a halt on many web pages, especially ones with video animation, to the point where I can't type because it drops multiple characters. I have to use an ad blocker to make pages workable. Is this normal or is there something wrong with my machine?
People seem to just be used to them and claim that their computers are ‘getting slower’, but really they don’t use their computer for anything but web browsing and it’s only slower because ads are getting worse and worse.
Why not just downsample the original image to 10x10 jpg and encode it as base64 so it can be directly used in an <img> without blocking your main JS thread to decode the image? Apply css blur if you like the soft gradient effect.
I'm experiencing bad connections all the time, especially while travelling. Additionally, mobile plans are quite expensive in Germany compared to many other countries. So yes, I try to save bandwidth when possible, e.g. by offering AVIF and WebP in addition to PNG and JPEG files on my blog.
It’s a joy to use when it resolves those placeholders piece by piece into the original