Problem:
I have a variable that contains 192 images in the following way:
<script>
var stimuli = '.json_encode($_SESSION['stimuli'], JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT).';
</script>
An example of each item is as follows:
{
"image": "assets/materials/4233.png",
"correct_response": "c",
"evaluationnumber": 3649,
"type": "f",
"stimulustype": "F3aC",
"item": 4233
},
In my JS file I try to preload all images using the following:
stimuli.forEach(({image}) => loadImage(image));
loadImage()
is as follows:
const loadImage = (src) => new Promise((resolve, reject) => {
const img = new Image();
img.addEventListener("load", () => resolve(img));
img.addEventListener("error", err => reject(err));
img.src = src;
});
When I check the network-tab, only 32 images are preloading and not 192.
Questions
- What might be the cause that only 32 of 192 images preload?
- How can I rewrite the code to ensure that all 192 images preload?