For one of my client's brochure websites, I am using the Bootstrap carousel. The carousel has 6 panels, each displaying a fairly large image.
To speed initial load time, I'm toying with the idea of only including two panels in the page's source, and somehow using JavaScript to append additional panels after the page is loaded to the DOM. That is, I want to lazy load additional panels to the carousel; hopefully they'll be in place before the carousel needs to display them (my carousel is set to change panels every 4 seconds, so two initial panels gives me 8 seconds to append a third panel).
How can I add panels to an existing carousel?
HTML:
<div id="home_pictures" class="carousel slide">
<!-- Carousel items -->
<div class="carousel-inner">
<div class="active item">
<img src="img/carousel_wellness.jpg" alt="Wellness: Comprehensive approaches for your individual needs" />
<div class="container">
<div class="carousel-caption">
<h2>Wellness</h2>
<p class="lead">Comprehensive approaches for your individual needs</p>
</div>
</div>
</div>
<div class="item">
<img src="img/carousel_psychotherapy.jpg" alt="Psychotherapy: Increase your sense of your own well-being" />
<div class="container">
<div class="carousel-caption">
<h2>Psychotherapy</h2>
<p class="lead">Increase your sense of your own well-being</p>
</div>
</div>
</div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#home_pictures" data-slide="prev">‹</a>
<a class="carousel-control right" href="#home_pictures" data-slide="next">›</a>
</div>