Pages

Monday, August 20, 2012

Loading jquery/javascript libraries from CDN if online etc local


I added some local flags too to enforce local loading : if they're not present then normal offline/online checks are done on the first library in the onlineJavaScriptLibs array. Short and sweet. See the code image here. I realise that the test for the first jquery lib using fopen doesnt gaurentee the others are there but if thats not there there are worse things. I could check for each and every library but meh. Even then php pass doesnt really guarentee the client can access the online library. The fopen checks looking for offlinejs work on a per web (custom/offlinejs) or on an all web (lib/offlinejs) and is really there for people testing/running my framework using a local code base where they might be offline. I had tried the method of loading jquery and then checking in javascript if window.jQuery was defined but simply couldnt get the document.write() method working : I then tried using jquery to append newly constructed script/link objects to body for the offline/onlie scripts but , well, it simply didnt work. Work effort v covenience v results.