UPDATE
ho fatto un po 'di più un'indagine del problema e si possono trovare più dettagliate answer in my recent post nota, la soluzione descritta di seguito (inizialmente) non è una soluzione cross browser.
Non sono sicuro che sia d'aiuto, ma puoi provare il trucco seguente: 1. Aggiungi una risorsa alla tua pagina, diciamo che sarà il file javascript cachedetect.js
. 2. Il server dovrebbe generare cachedetect.js
ogni volta che qualcuno lo richiede. E dovrebbe contenere intestazioni relative alla cache in risposta, vale a dire se la cache del browser è abilitata, la risorsa dovrebbe essere memorizzata nella cache per un lungo periodo. Ogni cachedetect.js
dovrebbe assomigliare a questo:
var version = [incrementally generated number here];
var cacheEnabled; //will contain the result of our check
var cloneCallback;//function which will compare versions from two javascript files
function isCacheEnabled(){
if(!window.cloneCallback){
var currentVersion = version;//cache current version of the file
// request the same cachedetect.js by adding <script> tag dynamically to <header>
var head = document.getElementsByTagName("head")[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "cachedetect.js";
// newly loaded cachedetect.js will execute the same function isCacheEnabled, so we need to prevent it from loading the script for third time by checking for cloneCallback existence
cloneCallback = function(){
// once file will be loaded, version variable will contain different from currentVersion value in case when cache is disabled
window.cacheEnabled = currentVersion == window.version;
};
head.appendChild(script);
} else {
window.cloneCallback();
}
}
isCacheEnabled();
Dopo di che si può semplicemente verificare la presenza di cacheEnabled === true
o cacheEnabled === false
dopo un certo periodo di tempo.
fonte
2012-02-09 01:04:04
Cosa intendi dicendo "il browser è ottimizzato per il caching"? Supporta etag o qualche intestazione della cache specifica? –
È possibile disabilitare la memorizzazione di file statici nelle impostazioni del browser. C'è un modo per testare se quella memoria è disabilitata? – gaffleck