Warm tip: This article is reproduced from serverfault.com, please click

Why does Html img tag only allow a maximum of 6 src to the same host?

发布于 2020-12-04 13:55:45

I am trying to request 10 streams from the same host using img tag but it can only go to a maximum of six, but if I combine ip addresses with hostnames it does work.

Below is the html I use.

<div class="container-fluid">
  <h1> Streams </h1>
  <div class="row">
    <div *ngFor="let idx of streams" class="col-md-3">
        <img [src]="idx" alt="">
      <br/>
    </div>
  </div>
</div>

Working solution: If I combine ip addresses with hostnames it works.

 streams = [
    'http://jetson1.local:8085/api/stream/accc8ee8f2c5',
    'http://jetson1.local:8085/api/stream/bcad28d47b1c',
    'http://jetson1.local:8085/api/stream/4447cc9d2a8714',
    'http://jetson1.local:8085/api/stream/0013e2fa6841',
    'http://192.168.51.76:8085/api/stream/48ea63a53318',
    'http://192.168.51.76:8085/api/stream/0013e2fa67dc',
    'http://192.168.51.76:8085/api/stream/08eded8744a1',
    'http://192.168.51.76:8085/api/stream/9c14633240be',
    'http://192.168.51.76:8085/api/stream/5804cb009268',
    'http://192.168.51.76:8085/api/stream/38af290fc271'
  ];

These don't work. If I define it like below it does not work.

 streams = [
    'http://192.168.51.76:8085/api/stream/accc8ee8f2c5',
    'http://192.168.51.76:8085/api/stream/bcad28d47b1c',
    'http://192.168.51.76:8085/api/stream/4447cc9d2a8714',
    'http://192.168.51.76:8085/api/stream/0013e2fa6841',
    'http://192.168.51.76:8085/api/stream/48ea63a53318',
    'http://192.168.51.76:8085/api/stream/0013e2fa67dc',
    'http://192.168.51.76:8085/api/stream/08eded8744a1',
    'http://192.168.51.76:8085/api/stream/9c14633240be',
    'http://192.168.51.76:8085/api/stream/5804cb009268',
    'http://192.168.51.76:8085/api/stream/38af290fc271'
  ];

Is it some sort of limitation based on the browser. I tried both on firefox and chrome. If so, how can one overcome this?

It just shows pending.

enter image description here

Questioner
kg99
Viewed
0
Masklinn 2020-12-04 22:14:20

This has nothing to do with the img tag. The browsers themselves limit the number of connections they maintain to any given domain to somewhere between 2 and 15 (all modern browsers use 6).

If so, how can one overcome this?

"Don't do it" would be the best solution.

Alternatively you can serve from multiple subdomains, but then you risk hitting the global connections limit (between 10 and 20 on modern browsers). An other mitigation technique is to use HTTP/2, such that multiple requests can be multiplexed on a single connection. The final alternative would be to use websocket instead of more naive streams, websocket has a much higher connection limit than HTTP (200+, though chrome used to have a much lower limit of 30 / host)