CẬP NHẬT
tôi đã điều tra thêm một chút của vấn đề và bạn có thể tìm thấy chi tiết hơn answer in my recent post Lưu ý, các giải pháp được mô tả dưới đây (ban đầu) không phải là giải pháp trình duyệt chéo.
Không chắc chắn nếu nó có ích, nhưng bạn có thể thử mẹo sau: 1. Thêm một số tài nguyên vào trang của bạn, giả sử nó sẽ là tệp javascript cachedetect.js
. 2. Máy chủ sẽ tạo ra cachedetect.js
mỗi lần ai đó yêu cầu. Và nó phải chứa tiêu đề liên quan đến bộ nhớ cache để phản hồi, tức là nếu bộ nhớ cache của trình duyệt được bật, tài nguyên sẽ được lưu trong bộ nhớ cache trong thời gian dài. Mỗi cachedetect.js
sẽ trông như thế này:
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();
Sau đó bạn chỉ có thể kiểm tra cacheEnabled === true
hoặc cacheEnabled === false
sau một khoảng thời gian.
Nguồn
2012-02-09 01:04:04
gì bạn có nghĩa là trong khi nói "trình duyệt được tối ưu hóa cho bộ nhớ đệm"? Nó có hỗ trợ etag hoặc một số tiêu đề bộ nhớ cache cụ thể không? –
Bạn có thể tắt lưu trữ các tệp tĩnh trong cài đặt trình duyệt. Có cách nào để kiểm tra xem bộ nhớ đó có bị vô hiệu không? – gaffleck