how to generate headJS fallbacks

317 Views Asked by At

How can I properly implement fallback for headJS and Jquery (if the CDN fails to load) within the head load function?

I cant find anything on the documentation about fallbacks.

http://headjs.com/

My code is the following: (right now HeadJS and Jquery are loaded from CDN)

<script src="//cdnjs.cloudflare.com/ajax/libs/headjs/1.0.3/head.min.js"></script>
<script>
// this loads jquery asyncrounously & in parallel
head.load("//cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js", "script1", "script2");
if (head.screen.innerHeight < 800) {
    /* code specific to VIEWPORT < 800 */
    head.load("{T_THEME_PATH}/footable/js/footable.min.js");
    head.ready(function () {
        // some callback stuff
        $('.footable').footable();
    });
}
</script>
1

There are 1 best solutions below

0
On BEST ANSWER

Here the answer wit headJS. run a test and fallback to something else like this

head.load({"jquery": "...path to cdn"});

and then

head.ready("jquery", function() {
    if (!window.jQuery) {
        head.load({"jquery": "...path to fallback"});
    }
});