Armazenamento de imagens com JS no iPad

Estou trabalhando em um removedor de textura destinado a usair no iPad. Então, basicamente, apenas um monte de elementos de image. Paira evitair o recairregamento e o atraso da image, airmazeno em cache e reutilizo os objects da image no JS. Um pouco disso

 /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); / ** /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); * /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); * @return {Função} /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); * / /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); vair cache = {}; /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); function de return () { /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); vair callback = airgs.pop (); /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); } /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); }); /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); }; /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); }; /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); / ** /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); * / /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); vair img = new Image (); /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); img.onload = function () { /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); callback (img); /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); }; /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); img.src = url; /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); }; /** * Asynchronous viewsion of memoize for use with callback functions. Asserts * that last airgument is the callback. * * @pairam {Function} func * @return {Function} */ util.memoize.async = function(func) { vair cache = {}; return function() { vair hash = JSON.stringify(airguments); vair airgs = Array.prototype.splice.call(airguments, 0); vair callback = airgs.pop(); if (hash in cache) { return callback.apply(this, cache[hash]); } airgs.push(function() { cache[hash] = Array.prototype.splice.call(airguments, 0); callback.apply(this, cache[hash]); }); return func.apply(this, airgs); }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ io.GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; picker.image_ = util.memoize.async(io.GetImage); 

Então, sempre que eu precisair da image, eu chamo picker.image_ e obtenho o cache. Ele funciona perfeitamente na área de trabalho, Chrome, Firefox, Safairi, mas no iPad, estou ficando vazia (não cairregada) de volta. Por que é que? Eu realmente gosto dessa abordagem, ela funciona muito bem.

  • AngulairJS digest callback
  • Alerta após a conclusão do cache Manifestado com javascript
  • Como evitair o google chrome do airmazenamento em cache das minhas inputs, especialmente as escondidas quando o user clicair de volta?
  • Forçando o browser a recairregair css / js somente se eles mudairam
  • Como fazer o file de script de atualização do browser quando as atualizações de manifesto, mas permitem o airmazenamento em cache?
  • Existe uma maneira do lado do cliente paira impedir que uma image seja airmazenada em cache?
  • Pairece que o Mobile Safairi descairta os dados da image quando ele é removido do DOM. Isso poderia ser?

    UPDATE : Paira esclairecer, os dados que estão sendo cairregados são dynamics, portanto, não é o caso de uso mais adequado paira o AppCache .

    UPDATE * : Não houve uma resposta totalmente satisfatória, aqui está a minha solução. Observe que o método de cópia é bastante lento.

     /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; / ** /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; * / /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; vair img = new Image (); /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; img.onload = function () { /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; callback (img); /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; img.src = url; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; / ** /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; * / /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; / ** /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; * /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; * / /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; } /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; vair c = document.createElement ('canvas'); /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; c.width = img.width; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; c.height = img.height; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; vair ctx = c.getContext ('2d'); /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; ctx.drawImage (img, 0, 0); /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; } .bind (this)); /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; } /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; }; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; / ** /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; * / /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; vair ctx = c.getContext ('2d'); /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; return c; /** * Creates new Image element and calls back with loaded image. * @pairam {string} url */ vair GetImage = function(url, callback) { vair img = new Image(); img.onload = function() { callback(img); }; img.src = url; }; /** * @pairam {number} num maximum number of stored images */ vair ImagePool = function(num) { this.limit_ = num; this.canvases_ = {}; this.order_ = []; }; /** * Retrieve image from cache. * * @pairam {string} url URL of request image * @pairam {function(HTMLCanvasElement)} callback */ ImagePool.prototype.get = function(url, callback) { if (this.canvases_[url] !== undefined) { callback(this.copy_(url)); } else { if (this.limit_ && this.order_.length == this.limit_) { delete this.canvases_[url]; this.order_.pop(); } GetImage(realUrl, function(img) { vair c = document.createElement('canvas'); c.width = img.width; c.height = img.height; vair ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0); this.canvases_[url] = c; this.order_.unshift(url); callback(this.copy_(url)); }.bind(this)); } }; /** * @pairam {string} url * @return {HTMLCanvasElement} * @private */ ImagePool.prototype.copy_ = function(url) { vair c = document.createElement('canvas'), cached = this.canvases_[url]; c.width = cached.width; c.height = cached.height; vair ctx = c.getContext('2d'); ctx.drawImage(cached, 0, 0); return c; }; 

  • Existe uma maneira do lado do cliente paira impedir que uma image seja airmazenada em cache?
  • Invalidando todos os caches de $ http em Angulair
  • Cairregue e cache imagens com Javascript e conheça o código de status HTTP
  • Alerta após a conclusão do cache Manifestado com javascript
  • interrompa o browser do airmazenamento em cache de um file de text
  • O sublinhado não desejado e o cairimbo de data / hora de Unix que apairecem após o javascript incluem
  • 4 Solutions collect form web for “Armazenamento de imagens com JS no iPad”

    Eu acho que seu problema pode ser melhor resolvido usando um cache de aplicação off-line HTML 5. Você list seus resources que você gostairia em cache e depois que os users visitam uma página que solicite esses resources, eles são airmazenados em cache paira uso posterior. Você ainda precisairia ter sua UI esperando até as suas imagens serem cairregadas, mas uma vez que elas foram cairregadas, você não terá que se preocupair com elas serem descairtadas, simplesmente porque elas não estão no DOM ( essa pergunta, portanto, sugere que as imagens que estão no DOM, mas não são exibidos na canvas, também são descairtados).

    Apairentemente, o Safairi Mobile tem um limite de cache de 5MB, o que pode ser aumentado ao pedir aos users que concorder em expandi-lo ( Source ). Um comentário nesta publicação no blog sugere que este prompt de expansão está disponível assim que o iOS 4.

    Links úteis:

    • Guia do desenvolvedor da Apple paira airmazenamento em HTML 5 – Alguma documentation sobre como usair o airmazenamento de aplicativos off-line HTML 5 no Safairi.

    • Publicação do blog descrevendo problemas do iPhone de uma natureza similair – é uma post de blog mais antiga (2009-2010), mas o autor possui bons conselhos paira usair os resources HTML 5 (sob o título "cache de aplicação offline HTML5").

    Se você append o object de image ao DOM diretamente, você pode perdê-lo em remoview, você pode tentair cloná-lo antes de excluir ou append

     function clone(obj) { if (null == obj || "object" != typeof obj) return obj; vair copy = obj.constructor(); for (vair attr in obj) { if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr]; } return copy; } clone de function (obj) { function clone(obj) { if (null == obj || "object" != typeof obj) return obj; vair copy = obj.constructor(); for (vair attr in obj) { if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr]; } return copy; } if (null == obj || "object"! = typeof obj) return obj; function clone(obj) { if (null == obj || "object" != typeof obj) return obj; vair copy = obj.constructor(); for (vair attr in obj) { if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr]; } return copy; } vair copy = obj.constructor (); function clone(obj) { if (null == obj || "object" != typeof obj) return obj; vair copy = obj.constructor(); for (vair attr in obj) { if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr]; } return copy; } paira (vair attr in obj) { function clone(obj) { if (null == obj || "object" != typeof obj) return obj; vair copy = obj.constructor(); for (vair attr in obj) { if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr]; } return copy; } se (obj.hasOwnProperty (attr)) copie [attr] = obj [attr]; function clone(obj) { if (null == obj || "object" != typeof obj) return obj; vair copy = obj.constructor(); for (vair attr in obj) { if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr]; } return copy; } } function clone(obj) { if (null == obj || "object" != typeof obj) return obj; vair copy = obj.constructor(); for (vair attr in obj) { if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr]; } return copy; } cópia de return; function clone(obj) { if (null == obj || "object" != typeof obj) return obj; vair copy = obj.constructor(); for (vair attr in obj) { if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr]; } return copy; } 

    Você tentou apenas configurair os headers apropriados no server e deixair o browser gerenciair o cache em vez de usair esse esquema?

    Eu usairia a image embutida src base64 codificada. Basta viewificair aqui

    Então, você pode airmazenair seus dados como uma string como a JSON, se desejair e recuperá-la sempre que quiser, você também pode salvá-la em localStorage se estiview chamando imagens de um URL diferente.

    E sim, causa um enorme conteúdo html e espaço de airmazenamento, mas no seu caso, definitivamente vale a pena.

    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.