This function clones sound objects for a list of images.
The problem is that when the object is written in the DOM, the browser querys the server loads it as a 200 request. However, it is only loading 4 different sound files, over and over again. So it should load as a 304 request from the browser's cache.
All of the sound files are initially loaded in HTML and then cloned. Whenever the page is refreshed the sound files in the HTML receive 304 requests and are loaded from cache, but any file that is cloned is loaded with 200 request (not from cache)!
It there anyway for me to clone these objects without the browser sending a request to the server to load into DOM? Just totally on client side? The data is already written once in the HTML.
I would prefer not to send any requests to the server at all to clone these objects. Since it clones over 50, that's 50 requests being sent to the server in a second. Overloading it.
var increment = 0;
$("img").each(function(i) { //loop for each item
if (increment > 4){
increment = 0;
}
if (i != 0) { //only clone if there are more than one 'img' items
$("#hover-" + increment) //item to clone
.clone(true)
.attr("id", "beep-" + i) //new name of object
.appendTo($(this).parent());
}
$(this).data("instance", i); //save the integer for loop
increment=Math.floor(Math.random()*3); //change increment
})