vendredi 5 février 2016

Avoiding multiple load of javascript file

I add this snippet to each javascript file used in my asp.net web api application to avoid multiple load :

Fullcalendar.js

blog = {};
blog.comments = blog.comments || {};
blog.comments.debugMode = false;

blog.isFirstLoad = function (namesp, jsFile) {
    var isFirst = namesp.jsFile.firstLoad === undefined;
    namesp.jsFile.firstLoad = false;
    return isFirst;
};

$(document).ready(function () {
    if (!blog.isFirstLoad(blog.comments, "fullcalendar.js")) {
        return;
    }
});

Sometimes I get a weird exception

Uncaught TypeError: Cannot read property 'firstLoad' of undefined

I need to know :

  1. Why this happens?
  2. How can I fix it?



Aucun commentaire:

Enregistrer un commentaire