News for hackers. Stuff that matters.
Re:WebP: The WebPage Compression Format by BugsJustFindMe on Saturday September 07, 2024 @02:31PM (#41475528)
> the longest post on my site, takes 92 KiB instead of 37 KiB. This amounts to an unnecessary 2.5x increase in load time

Sure, if you ignore latency. In reality it's an unnecessary 0.001% increase in load time because that size increase isn't enough to matter vs the round trip time. And the time you save transmitting 55 fewer KiB is probably less than the time lost to decompression. :p

While fun, I would expect this specific scenario to actually be worse for the user experience not better. Speed will be a complete wash and compatibility will be worse.

Re:WebP: The WebPage Compression Format by edflsafoiewq on Saturday September 07, 2024 @03:29PM (#41475879)
Well, that, and there's an 850K Symbols-2048-em%20Nerd%20Font%20Complete.woff2 file that sort of drowns out the difference, at least if it's not in cache.
Re:WebP: The WebPage Compression Format by lxgr on Saturday September 07, 2024 @05:12PM (#41476495)
Now I got curious, and there's also a 400 kB CSS file to go with it: https://purplesyringa.moe/fonts/webfont.css

I'm not up to date on web/font development – does anybody know what that does?

Re:WebP: The WebPage Compression Format by bobbylarrybobby on Saturday September 07, 2024 @05:24PM (#41476572)
It adds unicode characters before elements with the given class. Then it's up to the font to display those Unicode characters — in this case, based on the class names, one can infer that the font assigns an icon to each character used.
Re:WebP: The WebPage Compression Format by lxgr on Saturday September 07, 2024 @05:31PM (#41476606)
That makes sense, thank you!

So the purpose is effectively to have human-readable CSS class names to refer to given glyphs in the font, rather than having stray private use Unicode characters in the HTML?

Re:WebP: The WebPage Compression Format by lobsterthief on Saturday September 07, 2024 @05:41PM (#41476646)
Yep

This is a reasonable approach if you have a large number of icons across large parts of the site, but you should always compile the CSS/icon set down to only those used.

If only a few icons, and the icons are small, then inlining the SVG is a better option. But if you have too many SVGs directly embedded on the site, the page size itself will suffer.

As always with website optimization, whether something is a good option always “depends”.

Re:WebP: The WebPage Compression Format by lifthrasiir on Sunday September 08, 2024 @12:02AM (#41478127)
I think at least some recent tools will produce ligatures to turn a plain text into an icon to avoid this issue.
Re:WebP: The WebPage Compression Format by alpaca128 on Sunday September 08, 2024 @08:12AM (#41479944)
Another detail is that this feature breaks and makes some sites nearly unusable if the browser is set to ignore a website's custom fonts.
Re:WebP: The WebPage Compression Format by yencabulator on Sunday September 08, 2024 @10:46AM (#41480713)
More reasonable than this class+CSS would be e.g. a React/static-website-template/etc custom element that outputs the correct glyph. The output doesn't need to contain this indirection, and all of the possibilities.
Re:WebP: The WebPage Compression Format by marcellus23 on Saturday September 07, 2024 @05:28PM (#41476594)
Wow, yeah. That kind of discredits the blog author a bit.
Re:WebP: The WebPage Compression Format by edflsafoiewq on Saturday September 07, 2024 @05:38PM (#41476635)
I mean, it's all just for fun of course.
Re:WebP: The WebPage Compression Format by purplesyringa on Sunday September 08, 2024 @04:10AM (#41478951)
It's cached. Not ideal, sure, and I'll get rid of that bloat someday, but that file is not mission-critical and the cost is amortized between visits. I admit my fault though.
Re:WebP: The WebPage Compression Format by marcellus23 on Sunday September 08, 2024 @11:24AM (#41480935)
Definitely fair and I was a bit harsh. It just seemed a bit nonsensical to go through such efforts to get rid of a few kilobytes while serving a massive font file. But I also understand that it's mostly for fun :)
Re:WebP: The WebPage Compression Format by Modified3019 on Sunday September 08, 2024 @09:53PM (#41484844)
As usual, the quickest way to optimize a webpage is to show HN how you tried to do so lol

Definitely a fascinating post though, there were things I’ve not encountered before.

Re:WebP: The WebPage Compression Format by account42 on Monday September 09, 2024 @05:21AM (#41486760)
> It's cached.

For who? Not for 99.9% of the people clicking the link here on HN. Even regular visitors of a blog will likely no longer have things in cache for their next visit.

Re:WebP: The WebPage Compression Format by est on Saturday September 07, 2024 @11:23PM (#41477978)
seriously, why can't modern browsers turn off features like remote fonts, webrtc, etc. in settings. I hate when reading a bit then the font changes. Not to say fingerprinting risks.
Re:WebP: The WebPage Compression Format by BugsJustFindMe on Sunday September 08, 2024 @12:54AM (#41478286)
You can, and then when someone uses an icon font instead of graphics their page breaks.
Re:WebP: The WebPage Compression Format by Dalewyn on Sunday September 08, 2024 @01:19AM (#41478348)
Skill issue.

Pictures are pictures, text is text. <img> tag exists for a reason.

Re:WebP: The WebPage Compression Format by lenkite on Sunday September 08, 2024 @04:09AM (#41478948)
Its a convenience packaging issue. An icon font is simply more convenient to handle. <img> tags for a hundred images requires more work.

Icon fonts are used all over the place - look at the terminal nowadays. Most TUI's require an icon font to be installed.

Re:WebP: The WebPage Compression Format by Dalewyn on Sunday September 08, 2024 @01:47PM (#41481849)
><img> tags for a hundred images requires more work.

So it's a skill issue.

Re:WebP: The WebPage Compression Format by est on Sunday September 08, 2024 @07:40AM (#41479811)
I believe many Web APIs can be enabled/disabled on a website basis, no?
Re:WebP: The WebPage Compression Format by collinmanderson on Sunday September 08, 2024 @09:01AM (#41480153)
iPhone lock down mode turns off remote fonts (including breaking font icons as sibling says)
Re:WebP: The WebPage Compression Format by Aloisius on Sunday September 08, 2024 @07:43PM (#41484240)
Even the gzipped page itself could be shrunk by 40-50% by optimizing the inline SVGs.

Just removing the inline duplicated SVGs used for light/dark mode and using styles instead would bring it down 30%. Replacing the paths used to write text (!) with <text> and making most of the overly complicated paths into simple rect patterns would take care of the rest.

Re:WebP: The WebPage Compression Format by jsnell on Saturday September 07, 2024 @02:40PM (#41475574)
That size difference is large enough to make a difference in the number of round trips required (should be roughly one fewer roundtrip with any sensible modern value for the initial congestion window).

Won't be a 2.5x difference, but also not 0.001%.

Re:WebP: The WebPage Compression Format by BugsJustFindMe on Saturday September 07, 2024 @02:52PM (#41475650)
You don't need a new roundtrip for every packet. That would be devastating for throughput. One vs two vs three file packets get acked as a batch either way, not serially.

Also when you get to the end, you then see

> The actual savings here are moderate: the original is 88 KiB with gzip, and the WebP one is 83 KiB with gzip. In contrast, Brotli would provide 69 KiB.

At 69 KiB you're still over the default TCP packet max, which means both cases transmit the same number of packets, one just has a bunch of extra overhead added for the extra JavaScript fetch, load, and execute.

The time saved here is going to be negligible at best anyway, but there looks to be actually negative because we're burning time without reducing the number of needed packets at all.

Re:WebP: The WebPage Compression Format by jsnell on Saturday September 07, 2024 @03:12PM (#41475770)
Those numbers are for a different page. For the original page, the article quotes 44 kB with this method vs. 92 kB for gzip.

> At 69 KiB you're still over the default TCP packet max, which means both cases transmit the same number of packets,

What? No, they absolutely don't transmit the same number of packets. Did you mean some other word?

Re:WebP: The WebPage Compression Format by mananaysiempre on Saturday September 07, 2024 @04:11PM (#41476170)
I expect what GP meant is the default TCP window size, so in a situation where bandwidth costs are dwarfed by roundtrip costs, these two cases will end up taking essentially the same time, because they will incur the same number of ACK roundtrips. Don’t know if the numbers work out, but that at least sounds plausible.
Re:WebP: The WebPage Compression Format by BugsJustFindMe on Saturday September 07, 2024 @05:18PM (#41476531)
Yes, sorry
Re:WebP: The WebPage Compression Format by jsnell on Saturday September 07, 2024 @07:28PM (#41477081)
No, there is no way the numbers would work out to the same number of roundtrips. The sizes are different by a factor of 2.5x, and the congestion window will only double in a single roundtrip. The only way the number of roundtrips would be the same is if both transfers fit in the initial congestion window.
Re:WebP: The WebPage Compression Format by codetrotter on Saturday September 07, 2024 @04:09PM (#41476153)
They were probably thinking of the max size for packets in TCP, which is 64K (65535 bytes).

However, Ethernet has a MTU (Maximum Transmission Unit) of 1500 bytes. Unless jumbo frames are used.

And so I agree with you, the number of packets that will be sent for 69 KiB vs 92 KiB will likely be different.

Re:WebP: The WebPage Compression Format by pierrec on Saturday September 07, 2024 @03:25PM (#41475847)
Interesting, how does that add a round trip? For the record here's what I believe to be the common definition of an additional "round trip", in a web development context:

  - client requests X
  - client gets X, which contains a reference to Y
  - therefore client requests Y
So you're starting a new request that depends on the client having received the first one. (although upon closer inspection I think the technique described in the blog post manages to fit everything into the first response, so I'm not sure how relevant this is)
Re:WebP: The WebPage Compression Format by jsnell on Saturday September 07, 2024 @03:40PM (#41475952)
Unless a resource is very small, it won't be transmitted in a single atomic unit. The sender will only send a part of it, wait the client to acknowledge having received them, and only then send more. That requires a network roundtrip. The larger the resource, the more network roundtrips will be required.

If you want to learn more, pretty much any resource on TCP should explain this stuff. Here's something I wrote years ago, the background section should be pretty applicable: https://www.snellman.net/blog/archive/2017-08-19-slow-ps4-do...

Re:WebP: The WebPage Compression Format by crote on Saturday September 07, 2024 @04:23PM (#41476260)
In reality it's more like:

  - client requests X
  - server sends bytes 0-2k of X
  - client acknowledges bytes 0-2k of X
  - server sends bytes 2k-6k of X
  - client acknowledges bytes 2k-6k of X
  - server sends bytes 6k-14k of X
  - client acknowledges bytes 6k-14k of X
  - server sends bytes 14k-30k of X
  - client acknowledges bytes 14k-30k of X
  - server sends bytes 30k-62k of X
  - client acknowledges bytes 30k-62k of X
  - server sends bytes 62k-83k of X
  - client acknowledges bytes 62k-83k of X
  - client has received X, which contains a reference to Y
  - therefore client requests Y
It's all about TCP congestion control here. There are dozens of algorithms used to handle it, but in pretty much all cases you want to have some kind of slow buildup in order to avoid completely swamping a slower connection and having all but the first few of your packets getting dropped.
Re:WebP: The WebPage Compression Format by notpushkin on Saturday September 07, 2024 @07:37PM (#41477124)
> client acknowledges bytes 0-2k of X

Doesn’t client see reference to Y at this point? Modern browsers start parsing HTML even before they receive the whole document.

Re:WebP: The WebPage Compression Format by Timwi on Sunday September 08, 2024 @12:55AM (#41478291)
Not just modern. This was even more significant on slow connections, so they've kind of always done that. One could even argue that HTML, HTTP (specifically, chunked encoding) and gzip are all intentionally designed to enable this.
Re:WebP: The WebPage Compression Format by account42 on Monday September 09, 2024 @05:34AM (#41486810)
Chunked encoding is required for the server to start sending the document before it has been fully generated (or the size becomes known) but nothing stops the client from parsing not yet complete documents without it.
Re:WebP: The WebPage Compression Format by Retr0id on Saturday September 07, 2024 @02:52PM (#41475649)
Why is there more latency?

Edit: Ah, I see OP's code requests the webp separately. You can avoid the extra request if you write a self-extracting html/webp polyglot file, as is typically done in the demoscene.

Re:WebP: The WebPage Compression Format by BugsJustFindMe on Saturday September 07, 2024 @02:56PM (#41475666)
It takes more time for your message to get back and forth between your computer and the server than it takes for the server to pump out some extra bits.

Even if you transmit the js stuff inline, the op's notion of time still just ignores the fact that it takes the caller time to even ask the server for the data in the first place, and at such small sizes that time swallows the time to transmit from the user's perspective.

Re:WebP: The WebPage Compression Format by Retr0id on Saturday September 07, 2024 @03:12PM (#41475772)
Here's a demo that only uses a single request for the whole page load: https://retr0.id/stuff/bee_movie.webp.html

It is technically 2 requests, but the second one is a cache hit, in my testing.

Re:WebP: The WebPage Compression Format by BugsJustFindMe on Saturday September 07, 2024 @03:15PM (#41475791)
That's fine, but if you're evaluating the amount of time it takes to load a webpage, you cannot ignore the time it takes for the client request to reach your server in the first place or for the client to then unpack the data. The time saved transmitting such a small number of bits will be a fraction of the time spent making that initial request anyway. That's all I'm saying.

OP is only looking at transmit size differences, which is both not the same as transmit time differences and also not what the user actually experiences when requesting the page.

Re:WebP: The WebPage Compression Format by purplesyringa on Sunday September 08, 2024 @04:12AM (#41478959)
Hmm? I'm not sure where you're taking that from. The webp is inlined.
Re:WebP: The WebPage Compression Format by Retr0id on Sunday September 08, 2024 @09:41AM (#41480355)
Ah, so it is! I was skim-reading and stopped at `const result = await fetch("compressor/compressed.webp");`
Re:WebP: The WebPage Compression Format by jgalt212 on Saturday September 07, 2024 @02:58PM (#41475683)
I have similar feelings on js minification especially if you're sending via gzip.
Re:WebP: The WebPage Compression Format by lxgr on Saturday September 07, 2024 @04:53PM (#41476428)
That's certainly reasonable if you optimize only for loading time (and make certain assumptions about everybody's available data rate), but sometimes I really wish website (and more commonly app) authors wouldn't make that speed/data tradeoff so freely on my behalf, for me to find out after they've already pushed that extra data over my metered connection.

The tragedy here is that while some people, such as the author of TFA, go to great lengths to get from about 100 to 50 kB, others don't think twice to send me literally tens of megabytes of images, when I just want to know when a restaurant is open – on roaming data.

Resource awareness exists, but it's unfortunately very unevenly distributed.

Re:WebP: The WebPage Compression Format by k__ on Saturday September 07, 2024 @05:38PM (#41476636)
We need a MoSh-based browser with gopher support.
Re:WebP: The WebPage Compression Format by nox101 on Saturday September 07, 2024 @09:01PM (#41477473)
and you'd need AI to tell you whats in the pictures because lots of restaurant sites just have photos of their menu and some designer with no web knowledge put their phone number, address, and hours in an image designed in Photoshop
Re:WebP: The WebPage Compression Format by tacone on Sunday September 08, 2024 @02:51AM (#41478661)
You're in for bad luck. Some time ago I tried some photos of pasta dishes with Gemini and it could not guess the recipe name.
Re:WebP: The WebPage Compression Format by mintplant on Sunday September 08, 2024 @02:09PM (#41481994)
I've found Gemini to be pretty terrible at vision tasks compared to the competition. Try GPT-4o or Claude-3.5-Sonnet instead.
Re:WebP: The WebPage Compression Format by zamadatix on Sunday September 08, 2024 @10:00AM (#41480442)
There is an interesting "Save-Data" header to let a site know which makes sense to optimize for on connection but it seems to be Chrome only so far https://caniuse.com/?search=save-data

I wish there was a bit of an opposite option - a "don't lazy/partially load anything" for those of us on fiber watching images pop up as we scroll past them in the page that's been open for a minute.

Re:WebP: The WebPage Compression Format by kelnos on Sunday September 08, 2024 @05:52PM (#41483544)
> ... on roaming data.

A little OT, and I'm not sure if iOS has this ability, but I found that while I'm traveling, if I enable Data Saver on my (Android) phone, I can easily go a couple weeks using under 500MB of cellular data. (I also hop onto public wifi whenever it's available, so being in a place with lots of that is helpful.)

My partner, who has an iPhone, and couldn't find an option like that (maybe it exists; I don't think she tried very hard to find it), blew through her 5GB of free high-speed roaming data (T-Mobile; after that you get 256kbps, essentially unusable) in 5 or 6 days on that same trip.

It turns out there's so much crap going on the background, and it's all so unnecessary for the general user experience. And I bet it saves battery too. Anything that uses Google's push notifications system still works fine and gets timely notifications, as IIRC that connection is exempt from the data-saving feature.

I've thought about leaving Data Saver on all the time, even when on my home cellular network. Should probably try it and see how it goes.

But overall, yes, it would be great if website designers didn't design as if everyone is on an unmetered gigabit link with 5ms latency...

Re:WebP: The WebPage Compression Format by YourOrdinaryCat on Sunday September 08, 2024 @06:25PM (#41483753)
Settings > Cellular > Cellular Data Options > Low Data Mode is the iOS equivalent.
Re:WebP: The WebPage Compression Format by lxgr on Sunday September 08, 2024 @10:55PM (#41485070)
I'm always using that on roaming data! Even then, Google Maps happily blows through hundreds of megabytes of photos within a couple of minutes of browsing for restaurants, probably for all the high-res photos in the reviews...
Re:WebP: The WebPage Compression Format by hahamaster on Monday September 09, 2024 @02:55AM (#41486071)
On iPhone you can set Low Data mode for all cellular data (and also for specific wifi networks).

She might have kept tapping Sync at the bottom of Photos even though iOS itself pauses it when in Low Data mode. iCloud Photos and video syncing is a data killer if you're on a holiday abroad, my wife takes hundreds of photos and videos a day, imagine what it does to data.

Re:WebP: The WebPage Compression Format by account42 on Monday September 09, 2024 @04:59AM (#41486666)
I do wish site authors wouldn't waste my bandwidth, but I wish much more they wouldn't waste my CPU and break usability in various ways like TFA's "solution" does. This is not a win even if you care deeply about optimizing sites.
Re:WebP: The WebPage Compression Format by sleepydog on Saturday September 07, 2024 @05:16PM (#41476515)
Seriously, if you're saving less than a TCP receive window's worth of space it's not going to make any difference to latency.

I suppose it could make a difference on lossy networks, but I'm not sure.

Re:WebP: The WebPage Compression Format by lelandfe on Saturday September 07, 2024 @05:42PM (#41476651)
If the blob contains requests (images, but also stylesheets, JS, or worst case fonts), it will actually instead be a net negative to latency. The browser's preload scanner begins fetching resources even before the HTML is finished being parsed. That can't happen if the HTML doesn't exist until after JS decodes it. In other words, the entire body has become a blocking resource.

These are similar conversations people have around hydration, by the by.

Re:WebP: The WebPage Compression Format by rrr_oh_man on Sunday September 08, 2024 @01:46AM (#41478430)
> These are similar conversations people have around hydration

For the uninitiated: https://en.m.wikipedia.org/wiki/Hydration_(web_development)

Re:WebP: The WebPage Compression Format by fsndz on Saturday September 07, 2024 @06:07PM (#41476756)
exactly what I thought too
Re:WebP: The WebPage Compression Format by zahlman on Saturday September 07, 2024 @07:41PM (#41477138)
Actually, I was rather wondering about that claim, because it seems accidentally cherry-picked. Regarding that post:

> This code minifies to about 550 bytes. Together with the WebP itself, this amounts to 44 KiB. In comparison, gzip was 92 KiB, and Brotli would be 37 KiB.

But regarding the current one:

> The actual savings here are moderate: the original is 88 KiB with gzip, and the WebP one is 83 KiB with gzip. In contrast, Brotli would provide 69 KiB. Better than nothing, though.

Most of the other examples don't show dramatic (like more than factor-of-2) differences between the compression methods either. In my own local testing (on Python wheel data, which should be mostly Python source code, thus text that's full of common identifiers and keywords) I find that XZ typically outperforms gzip by about 25%, while Brotli doesn't do any better than XZ.

Re:WebP: The WebPage Compression Format by lifthrasiir on Sunday September 08, 2024 @09:05AM (#41480163)
XZ was never considered to become a compression algorithm built into web browsers to start with. Brotli decoder is already there for HTTP, so it has been proposed to include the full Brotli decoder and decoder API as it shouldn't take too much effort to add an encoder and expose them.

Also, XZ (or LZMA/LZMA2 in general) produces a smaller compressed data than Brotli with lots of free time, but is much slower than Brotli when targetting the same compression ratio. This is because LZMA/LZMA2 uses an adaptive range coder and multiple code distribution contexts, both highly contribute to the slowness when higher compression ratios are requested. Brotli only has the latter and its coding is just a bitwise Huffman coder.

Re:WebP: The WebPage Compression Format by oefrha on Saturday September 07, 2024 @09:06PM (#41477484)
It’s not just decompression time. They need to download the whole thing before decompression, whereas the browser can decompress and render HTML as it’s streamed from the server. If the connection is interrupted you lose everything, instead of being able to read the part you’ve downloaded.

So, for any reasonable connection the difference doesn’t matter; for actually gruesomely slow/unreliable connections where 50KB matters this is markedly worse. While a fun experiment, please don’t do it on your site.

Re:WebP: The WebPage Compression Format by robocat on Sunday September 08, 2024 @08:29AM (#41480008)
Other major issues that I had to contend with:

1: browsers choose when to download files and run JavaScript. It is not as easy as one might think to force JavaScript to run immediately as high priority (which it needs to be when it is on critical path to painting).

2: you lose certain browser optimisations where normally many things are done in parallel. Instead you are introducing delays into critical path and those delays might not be worth the "gain".

3: Browsers do great things to start requesting files in parallel as files are detected with HTML/CSS. Removing that feature can be a poor tradeoff.

There are a few other unobvious downsides. I would never deploy anything like that to a production site without serious engineering effort to measure the costs and benefits.

Re:WebP: The WebPage Compression Format by hot_gril on Sunday September 08, 2024 @05:16PM (#41483284)
I wish ISPs would advertise latency instead of just bandwidth. It matters a lot for average users, especially now that bandwidth is generally plentiful.