I'm working in a templating system that uses a series of plugins to output some markup. One of these plugins is a gallery that contains multiple images. As the gallery sizes grow, load speed gets impacted and I'm trying to come up with a creative approach to work around it.
Here's an example:
{% plugin gallery %}
will become:
<div id="gallery">
<img src="sample.png" alt="Sample Image">
<img src="sample.png" alt="Sample Image">
<img src="sample.png" alt="Sample Image">
<img src="sample.png" alt="Sample Image">
<img src="sample.png" alt="Sample Image">
</div>
I can't control the content that's being output, only wrap it with additional HTML. This obviously results in 5 images being loaded
One technique to load images when you want them is to give them a fake attribute that you then turn into src when you want to load (e.g. ) but I can't edit that output.
Another idea I had was wrapping all the output with something to prevent load, like an HTML comment, and then stripping that off / using the data with some JavaScript to reconstruct the image elements as needed and append them back to the DOM. This seems hacky and I'm out of ideas.
Summary:
- I want to prevent images from loading so I can load them as I want them and control page load better.
- I cannot edit the markup of the image tags, but can wrap with additional markup.
- I'm constrained to client-side languages (HTML/JS). I cannot use server-side languages or modify the server itself in this situation.
Any other techniques that may work here?