0

Say an image is embedded in webpage, but the image is not on the server, not found, and the server responds to requests for the image with a 404 error.

The image is not displayed on the webpage, the actual HTTP response body is not displayed. A "broken image" icon is typically displayed instead.

I don't know if the answer to this question varies based on the server type, OS, or other variables...

Does the server generate the full 404 response for embedded files?
If it does, does the browser download the whole 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...

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.

henryaaron
  • 105
  • 4
  • I am not sure what do you mean by embedded files. Usually an "embedded" file in an html is an image or something that is loaded using a "data url" encoded in base64. Of course, such a resource can't throw a "404" since it is in another layer, after the http. – Florin Asăvoaie Jan 17 '18 at 05:29

1 Answers1

0

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.

Barry Pollard
  • 4,461
  • 14
  • 26
  • 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's a CDN... if Amazon's customers were using CloudFront they may not want to have Amazon's logo as the favicon for their resources. – henryaaron Jan 26 '18 at 23:08
  • Then replace it! I would expect it to have either a default favicon (that can be replaced) or just 404 it. To create a 1 pixel default favicon seems like such a micro optimisation to me. But maybe I’m wrong and it does save a lot of resources on both the server and client side. – Barry Pollard Jan 26 '18 at 23:32