Q1. In the context of asynchronous JavaScript and the need to ‘fetch’ data from the client-side, why can’t we just edit our image elements by its attribute src?
Q2. Why is the Blob conversion process necessary to go through?
Q3. What is the blob role?
e.g. Retrieving image file from JSON. (BTW, I extracted it from MDN webpage, mind the comments)
function fetchBlob(product) {
// construct the URL path to the image file from the product.image property
let url = 'images/' + product.image;
// Use fetch to fetch the image, and convert the resulting response to a blob
// Again, if any errors occur we report them in the console.
fetch(url).then(function(response) {
return response.blob();
}).then(function(blob) {
// Convert the blob to an object URL — this is basically an temporary internal URL
// that points to an object stored inside the browser
let objectURL = URL.createObjectURL(blob);
// invoke showProduct
showProduct(objectURL, product);
});
}