I need to load 3 images from another page. This is my code
<script> jQuery(document).ready(function($) { var ids = ['#sk6x4', '#sk6x4a', '#sk6x4c']; var tabs = ['#tab1', '#tab2', '#tab3']; function getInfo() { $.each(ids, function (i, id) { $.ajax('/my-url', { success: function(data){ var imgSrc = $(data).find(ids[i] + ' img').attr('src'); $(tabs[i] + ' img').attr('src', imgSrc); } }); }); } }); </script> <ul class="nav nav-tabs" role="tablist"> <li class="active" id="tab1"><img src="" id="imageTriangle"/></li> <li id="tab2"><img src="" id="imageArc"/></li> <li id="tab3"><img src="" id="imageScat"/></li> </ul> This code works but wery slow. Images load very slowly. How i can make it faster? What is the right way to load images by ajax?
P.S. Images are optimized
.eachlooping always makes the script slow tryforloops