El problema del peso de los ficheros Javascript siempre ha sido algo que ha preocupado mucho a los desarrolladores web, muchas veces debes suprimir efectos (realmente inutiles) para conseguir un peso apropiado para un fichero.
JSOC, JavaScript Objecto Cache, es un framework con el que podremos aprovecharnos de un sistema de cache para almacenar nuestra funcionalidad en el cliente. Esto obviamente iría perfecto para almacenar efectos gráficos de nuestras páginas y evitar la carga de líneas de código.
var xhttp = new xhttp(); // use your XMLHTTPRequest library of choice!
function setCache(n,v){
var respCode = jsoc.set(n, v);
alert('Data containing ' + n + ' was fetched and cached!');
}
function clearCacheItem(n){
var respCode = jsoc.remove(n);
alert('Data containing ' + n + ' is no longer cached.');
}
function cacheStuff(cName){
jsoc = new JSOC(); // JavaScript Object Cache
if(jsoc.get(cName) == undefined){
// this object is not cached, so grab it as usual, then cache it via your call-back function.
cacheName = cName; // set the global cacheName so that it's in scope for the call-back function.
loc = 'http://dev.webframeworks.com/assets/getMyData.txt';
xhttp.fetch(loc, 'responseProxy', {'method':'POST','type':'text'});
}else{
// grab your stuff from cache!
var cacheItem = eval(cName);
alert(cName + ' = ' + cacheItem);
}
}
function responseProxy(response){
var x = eval("("+ response+")");
setCache(cacheName, cacheName, x.articles[17].article.body); // this is where cache is set as mentioned above.
}
0 comentarios, 0 referencias
+
#