'Can server dynamically change image data as its being loaded by browser?

Is anything preventing a server from dynamically changing the data of an image as it's being loaded by the browser?

To better explain what I am asking let's slow time a little bit or imagine a really slow connection.

Browser lands on the page where it's just one in so after being done with parsing, layout calculation, painting or whatever browser needs to do before being able to start downloading the image data. Eventually, it asks for the image and the server begins streaming it back. The image starts being displayed from top to bottom as its getting more data from the server. Does the server have complete freedom to provide whatever data it wants as long as it adheres to the image format in question?

Let's say every pixel is random color or whatever resolution/size is being used for data chunks being exchanged? Or is there something preventing changing it while the download is in flight perhaps some kind of hash or any other mechanism?

I guess today's image formats are not being loaded in this top-down fashion so feel free to assume old formats, browsers, protocols or travel back in time where such a thing would be possible.

Disclaimer:

This question is out of pure curiosity I am not solving any problem. I don't have code to share demonstrating what I am trying to do as I am not trying to do anything, nor I am using any specific language or framework just me not knowing enough about how the internet and its series of tubes work to answer this weird question I have.



Solution 1:[1]

The best way to understand this is by explaining an example.

Okay, so first we declare the array with the useState hook. I added some values just for example, but they are not needed.

The function add() will create a new integer which will be the last integer of the array plus one, and then it will be added to the items array.

The function remove(item) filters the items array by receiving an item as an argument and then filtering it with the filter() JS method which removes all elements that do not pass the condition.

As you can see in the return Fragment the onClick event handler passes the item parameter and then the remove() function knows exactly which element to remove.

function List() {
  const [items, setItems] = useState([0, 1, 2]);

  const add = () => {
    let newInt = items[items.length - 1] + 1;
    setItems([...items, newInt]);
  };

  const remove = (item) => {
    let filteredArr = items.filter((el) => el !== item);
    setItems(filteredArr);
  };

  return [
    <Fragment>
      <p>
        <button onClick={() => add()}>+ Add Item</button>
      </p>
      {items.map((item, index) => {
        return (
          <p key={index}>
            {item}
            <button onClick={() => remove(item)}>x</button>
          </p>
        );
      })}
    </Fragment>
  ];
}

Note: I assume you know that import { useState } from "react"; and export default List; are needed so I did not added to the code.

Solution 2:[2]

What you are looking for is .filter which you can put in front of .map. Furthermore you need a variable to keep track of the ids that have been clicked/ deleted (if you don't want to actually remove them but instead just hide them).

const deletedItems = [1,2,3,4,5];

props.items
.filter(item => !deletedItems.includes(item.id))
.map(item => {
// ...
})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gass
Solution 2 Vincent Menzel