Überprüfen Sie, ob das Preload-Skript bereits ausgeführt wurde (Elemente befinden sich im Cache).

Ich habe diese jQuery AJAX-Funktion, die mit dem Aufruf von .JS auf jeder Seite im HTML geladen wird

Ich möchte eine if-Anweisung einfügen, die prüft, ob sich die Dateien, die ich vorab laden möchte, bereits im Cache befinden. Dies verhindert, dass das Skript den gesamten Inhalt auf jeder Seite ausführt. Sobald sich alles im Cache befindet, brauchen wir das nicht mehr. Und es ist zeitaufwändig, es auszuführen!

Hinweis: Ich möchte es auf jeder Seite haben, da ich dieses Preload überall dort haben möchte, wo der Client auf die Website gelangt. (nicht nur Hauptseite)

Hier ist die preload.js:

(function() {

Hier zum Einfügen der if-Anweisung sollte etwa Folgendes stehen:

if(xhr[src="myslide.swf"].status = 200);
alert('cached');

oder (Konzept) wenn sich myslide.swf im Cache befindet, dann mache nichts; sonst...

}else{
setTimeout(function(){
var xhr = new XMLHttpRequest();
xhr.open('GET', 'myslide.js');
xhr.send('');   
var xhr = new XMLHttpRequest();
xhr.open('GET', 'myslide.swf');
xhr.send('');
var xhr = new XMLHttpRequest();
xhr.open('GET', 'images.xml');
xhr.send('');
var xhr = new XMLHttpRequest();
xhr.open('GET', 'param.xml');
xhr.send('');
$.ajax({ 
type: "POST", 
url: "/javascript/getnames.php", 
data: "$list",
cache: true,
dataType:"json",
success: function(result) {
    Object.size = function(obj) {
    var size = 0, key;
    for (key in obj) {
    if (obj.hasOwnProperty(key)) size++;
      }
     return size;
    };
    // Get the size of an object
    var size = Object.size(result);
    var i = 0;
    for(i=0; i<size; i++) new Image().src = "/site/" + result[i];
                /*alert(result[X]);*/
            }
     });  //closes the ajax call
var splashArray = new Array();
// Load the Splash XML file and assign each image within to an array
$.get('/javascript/preloadGallery.xml', function(xml) {
    $('image', xml).each(function (i) {
            splashArray.push($(this).attr("src"));
    });
    work_with_splash();
});
function work_with_splash () {
    Object.size = function(obj) {
    var size = 0, key;
    for (key in obj) {
    if (obj.hasOwnProperty(key)) size++;
      }
     return size;
    };
    // Get the size of an object
    var size = Object.size(splashArray);
    var i = 0;
    for(i=0; i<size; i++) new Image().src = splashArray[i];
                /*alert(result[X]);*/   
} //closes the spalsh Call
}, 500);
};

})();   

Das ganze Skript funktioniert perfekt, das einzige, was ich vermisse, ist die if-Anweisung.

Danke für die Hilfe.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage