Am assuming that by 10 MB you mean the total size of all images and you have several images. I would also assume that this is your use-case (you might be purposefully showing high-res photos).
All these divs are hidden in the beginning and based on navigation,
these divs are shown one by one. There is a menu div which will
control the hiding and displaying of other divs
If you have a fixed number of such images as shown in the question, then one method you could apply is to load each image as and when required. i.e. as per your menu option when a div is shown, at that time load the image. This way the first image will be loaded along with the page load, and the rest will be loaded on demand. You may show a "loading" indicator during that time. Also, note that you will need to load-on-demand only once for each image, which will then be cached for re-use.
Here is a very simple and crude example:
Demo Fiddle: http://jsfiddle.net/abhitalks/rmx4so40/1/
You maintain an array holding all your image urls and cached state. Inititally, the cached state will be false for all images. We will then turn it on for every image we show. (At this point we are assuming that the images will be cached, there are scenarios where images may not be cached).
Next, wire up a load
event handler for images and put in your code to systemically show the current images and hide other, if required.
On your menu click, check the array if cached flag is on. If not, let the load
event handler take care. If yes, show the image right away.
Sample Snippet:
var images = [{'url': 'http://lorempixel.com/320/320', 'isCached': false },
{'url': 'http://lorempixel.com/321/321', 'isCached': false },
{'url': 'http://lorempixel.com/322/322', 'isCached': false },
{'url': 'http://lorempixel.com/323/323', 'isCached': false }
],
idx = 0, len = images.length;
displayImage(0); // intitially display first image on page load right away
$("#nxt").on("click", function() {
idx = (++idx % len); displayImage(idx);
});
$("#prv").on("click", function() {
idx = (idx + len - 1) % len; displayImage(idx);
});
$("img").on("load", function() { showImage($(this)); }); // handle load event on image
function displayImage(idx) {
var $currentImage = $("#d" + (idx + 1)).find("img");
$currentImage.attr('src', images[idx].url); // set the src from current array index
if (images[idx].isCached) { showImage($currentImage); } // if cached, show
else { images[idx].isCached = true; } // if not cached, let load handler work
}
function showImage($img) {
$("img").removeClass("show"); $img.addClass("show"); // your routine here
}
div { float: left; }
img {
width: 0; opacity: 0;
transition: width 100ms, opacity 1s 250ms;
}
img.show { width: auto; opacity: 1; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="prv">< Previous</button><button id="nxt">Next ></button>
<hr />
<div id="d1"><img /></div>
<div id="d2"><img /></div>
<div id="d3"><img /></div>
<div id="d4"><img /></div>