Does the server generate the full 404 response for embedded files?
Yes it does. As you say, the server does not know if it’s an embedded file or a stand alone request.
If it does, does the browser download the whole response?
Well it will down load the full HTML 404 page - but it will not download any images or other dependent resources on that 404 page. If you open the Developer tools you will see the full HTML response.
The thought the provoked this question is when I noticed some of the big CDNs have a transparent 1x1 ico where their /favicon.ico goes, instead of having nothing. The thought is that this 64B file (in one case) is smaller or requires less compute power than a 404 response...
I don’t really understand this. OK I get that the one pixel file will be smaller than a 404 but if going to the effort of creating a small favicon.ico file then why not create a real one? Or are you saying they create default favicon.ico file which you can then replace? Ok might be worth to do it for that I suppose.
It doesn't appear that any of the HTTP header fields have a way of indicating that the resource is embedded and if it 404s, a body is not required.
Correct. The referer
HTTP Header could indicate if the request came from a certain page, but you don’t know whether it’s because it was requested as part of the page load, or if someone right clicked on the page and asked to view the image as separate request.
In general I would spend more time fixing 404s than worry about optimising the size of your 404 pages. The easiest way to avoid wasting bandwidth on 404s for embedded resources is to make sure you don’t have any 404s!
Additionally, as mentioned above, only the HTML for the 404 page is downloaded so unless you have a ridiculously large 404 age, or don’t compress it (using gzip or brotli), then the size of it should be very small.
Perhaps, as you say, the favicon might be the exception to this advice if you are hosting customer sites since it’s asked for every single page (if not found and cached) but for a site you own and manage I’d not worry about this for the reasons given.