-3

Whenever a page loads, all its content like images, scripts, styles, are requested via a different HTTP request, this is what I have learned.

But why so? When the image is on same server, it is obvious, that the browser will request for other content. So, can't the server send the image inline with the page itself?

Sometimes, some browsers use NO IMAGE mode, but that can be included in the request itself.

Can't this decrease data traffic, if implemented?

PranshuKhandal
  • 739
  • 7
  • 19
  • *"can't the server send the image inline with the page itself?"* - The programmer can write the code to do exactly that: https://stackoverflow.com/questions/8499633/how-to-display-base64-images-in-html But overall, any changes you wish to propose to HTTP standards can indeed be proposed. There are a variety of documents and proposals at any given time: https://developer.mozilla.org/en-US/docs/Web/HTTP/Resources_and_specifications – David May 02 '19 at 13:14

1 Answers1

2

Because HTTP was designed as a way to retrieve documents, i.e. pages of text. Only later this was enriched with images, scripts and other external resources.

Not every request for a document needs all related resources, for example (text-only) crawlers or browsers who have all related resources cached already - they just want to retrieve the document itself.

As for inlining the external resources, yes, that can be done using <script> and <style> elements, and using inline image data, see How to display Base64 images in HTML?.

Using HTTP/2 a compatible browser/server pair one can also utilize server push, doing exactly what you expect the older HTTP versions to support. See HTTP 2 will support server push, what does this mean?.

Also, as technology evolves, things can get added to a protocol - if that protocol is open to backwards-compatible changes. This one can't be easily hacked into HTTP/1.1 in a way that would keep older browsers and servers working.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272