I have 1324 different small SVG images, all the same basic size, that I need to load as background images for 1324 different cells in a grid display. The cells into which they load have varying geometry, so the SVG backgrounds need to stretch or compress to fit. The code below creates this effect, but I am stuck when trying to figure out how to do it without excessive network requests, and the point of this posting is to ask whether anyone might be able to advise me about managing the network traffic aspect of the task.
To avoid 1324 separate requests, one per background image (if the images were in separate SVG files), I thought I should be able to combine the images in a single file and refer to them individually by a unique id attribute value (a "sprite stack"). The following minimal examples renders what I want the way I want it to look, but when I load the page while watching in the network monitor in Chrome I see that it fetches the file that contains the images every time I refer to a different id value. With my real data and 1324 images, the browsers (I'm testing with current versions of Chrome, Firefox, Edge, and Safari, all on MacOS) make 1324 requests and crash before they can finish loading everything.
If I have understood correctly, one purpose of a sprite stack is to load a group of small images with a single network request and then refer to different portions of that omnibus file to render a contained image. The minimal sample below illustrates that combining the images into a single file works, as does referring to specific subimages within it, but I've clearly failed to understand how to implement this approach in a way that realizes the goal of reducing network requests.
This is the main HTML file, which loads the background images from an auxiliary SVG file (below):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Gradient embedded background test</title>
<style>
div {
height: 200px;
width: 400px;
border: 1px solid black;
background-size: auto auto;
background-repeat: no-repeat;
}
#d1 {
height: 300px;
}
#d2 {
height: 500px;
}</style>
</head>
<body>
<h1>Hi, Mom!</h1>
<div style="background: url('test-background.svg#or')">Stuff</div>
<div style="background: url('test-background.svg#bl')">Stuff</div>
<div id="d1" style="background: url('test-background.svg#gr')">Stuff</div>
<div id="d2" style="background: url('test-background.svg#vi')">Stuff</div>
</body>
</html>
This is the auxiliary SVG file with the images:
<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none">
<style type="text/css">
.sprite {display:none;}
.sprite:target {display:inline;}
</style>
<defs>
<linearGradient id="yellowGradient" x1="0%" x2="0%" y1="0%" y2="100%">
<stop offset="0%" stop-color="yellow" stop-opacity="1"/>
<stop offset="6%" stop-color="yellow" stop-opacity="1"/>
<stop offset="20%" stop-color="yellow" stop-opacity=".6"/>
<stop offset="35%" stop-color="yellow" stop-opacity=".4"/>
<stop offset="50%" stop-color="yellow" stop-opacity=".3"/>
<stop offset="65%" stop-color="yellow" stop-opacity=".4"/>
<stop offset="80%" stop-color="yellow" stop-opacity=".6"/>
<stop offset="94%" stop-color="yellow" stop-opacity="1"/>
<stop offset="100%" stop-color="yellow" stop-opacity="1"/>
</linearGradient>
<linearGradient id="dodgerblueGradient" x1="0%" x2="0%" y1="0%" y2="100%">
<stop offset="0%" stop-color="dodgerblue" stop-opacity="1"/>
<stop offset="6%" stop-color="dodgerblue" stop-opacity="1"/>
<stop offset="20%" stop-color="dodgerblue" stop-opacity=".6"/>
<stop offset="35%" stop-color="dodgerblue" stop-opacity=".4"/>
<stop offset="50%" stop-color="dodgerblue" stop-opacity=".3"/>
<stop offset="65%" stop-color="dodgerblue" stop-opacity=".4"/>
<stop offset="80%" stop-color="dodgerblue" stop-opacity=".6"/>
<stop offset="94%" stop-color="dodgerblue" stop-opacity="1"/>
<stop offset="100%" stop-color="dodgerblue" stop-opacity="1"/>
</linearGradient>
<linearGradient id="violetGradient" x1="0%" x2="0%" y1="0%" y2="100%">
<stop offset="0%" stop-color="violet" stop-opacity="1"/>
<stop offset="6%" stop-color="violet" stop-opacity="1"/>
<stop offset="20%" stop-color="violet" stop-opacity=".6"/>
<stop offset="35%" stop-color="violet" stop-opacity=".4"/>
<stop offset="50%" stop-color="violet" stop-opacity=".3"/>
<stop offset="65%" stop-color="violet" stop-opacity=".4"/>
<stop offset="80%" stop-color="violet" stop-opacity=".6"/>
<stop offset="94%" stop-color="violet" stop-opacity="1"/>
<stop offset="100%" stop-color="violet" stop-opacity="1"/>
</linearGradient>
<linearGradient id="orangeGradient" x1="0%" x2="0%" y1="0%" y2="100%">
<stop offset="0%" stop-color="orange" stop-opacity="1"/>
<stop offset="6%" stop-color="orange" stop-opacity="1"/>
<stop offset="20%" stop-color="orange" stop-opacity=".6"/>
<stop offset="35%" stop-color="orange" stop-opacity=".4"/>
<stop offset="50%" stop-color="orange" stop-opacity=".3"/>
<stop offset="65%" stop-color="orange" stop-opacity=".4"/>
<stop offset="80%" stop-color="orange" stop-opacity=".6"/>
<stop offset="94%" stop-color="orange" stop-opacity="1"/>
<stop offset="100%" stop-color="orange" stop-opacity="1"/>
</linearGradient>
<linearGradient id="peruGradient" x1="0%" x2="0%" y1="0%" y2="100%">
<stop offset="0%" stop-color="peru" stop-opacity="1"/>
<stop offset="6%" stop-color="peru" stop-opacity="1"/>
<stop offset="20%" stop-color="peru" stop-opacity=".6"/>
<stop offset="35%" stop-color="peru" stop-opacity=".4"/>
<stop offset="50%" stop-color="peru" stop-opacity=".3"/>
<stop offset="65%" stop-color="peru" stop-opacity=".4"/>
<stop offset="80%" stop-color="peru" stop-opacity=".6"/>
<stop offset="94%" stop-color="peru" stop-opacity="1"/>
<stop offset="100%" stop-color="peru" stop-opacity="1"/>
</linearGradient>
<linearGradient id="limegreenGradient" x1="0%" x2="0%" y1="0%" y2="100%">
<stop offset="0%" stop-color="limegreen" stop-opacity="1"/>
<stop offset="6%" stop-color="limegreen" stop-opacity="1"/>
<stop offset="20%" stop-color="limegreen" stop-opacity=".6"/>
<stop offset="35%" stop-color="limegreen" stop-opacity=".4"/>
<stop offset="50%" stop-color="limegreen" stop-opacity=".3"/>
<stop offset="65%" stop-color="limegreen" stop-opacity=".4"/>
<stop offset="80%" stop-color="limegreen" stop-opacity=".6"/>
<stop offset="94%" stop-color="limegreen" stop-opacity="1"/>
<stop offset="100%" stop-color="limegreen" stop-opacity="1"/>
</linearGradient>
</defs>
<svg xmlns="http://www.w3.org/2000/svg" id="or" class="sprite" viewBox="0 0 100 50"
preserveAspectRatio="none" width="100%" height="100%">
<g>
<path d="M 10,0 L 90, 50" stroke="url('#orangeGradient')" stroke-width="6" fill="none"/>
</g>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" id="bl" class="sprite" viewBox="0 0 100 50"
preserveAspectRatio="none" width="100%" height="100%">
<g>
<path d="M 10,0 L 90, 50" stroke="url('#dodgerblueGradient')" stroke-width="6"
fill="none"/>
</g>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" id="gr" class="sprite" viewBox="0 0 100 50"
preserveAspectRatio="none" width="100%" height="100%">
<g>
<path d="M 10,0 L 90, 50" stroke="url('#limegreenGradient')" stroke-width="6"
fill="none"/>
</g>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" id="vi" class="sprite" viewBox="0 0 100 50"
preserveAspectRatio="none" width="100%" height="100%">
<g>
<path d="M 10,0 L 90, 50" stroke="url('#violetGradient')" stroke-width="6" fill="none"/>
</g>
</svg>
</svg>
I would be grateful for any advice anyone might be able to provide about how to avoid reloading the same SVG file once for every unique fragment identifier: 4 in the sample, but an unmanageable 1324 in the real data that led me to explore this approach. Thank you!

Are you very sure the file is reloaded?
Retrieval from cache will/can show in the Network tab:
(in this image I am doing client-side generation of SVG) but that is basically the same)