cachetest
Thursday, 15 March 07
UPDATE: This was already known and in a number of different ways! not sure the technique I proposed was used before. Link courtesy of a reddit user
An italian blogger claimed to be able to check the user's cache without actually revealing what the technique used is. I was too curious so trying to figured what kind of stuff he used I come up with a solution that works but turned out to not be what the original poster used (the original technique remains undisclosed).
Example (only tested with firefox):
Sites you visited recently:
Basically creating an image object and testing if img.complete is true just after the image creation we are able to test if the image is already in the memory cache of the browser. Because most sites have some kind of logo we can use this image to check if the user actually visited a given site, and send it back to our server via Ajax if needed.
Note that the memory cache expires in very little time! But even if I didn't tested it I'm pretty sure it's possible to make this system more reliable and working with the disk cache too just checking how much time the onload event takes in order to fire.
Btw in the simple form of complete checking this is the function I used:
function isInCache(imgurl) {
var i = new Image();
i.src=imgurl;
var retval = i.complete ? "yes" : "no";
if (!i.complete) {
i.src='';
try {delete(i);} catch (e) {};
}
return retval;
}
This is a big security problem but I guess it's pretty hard to fix it without to impact in some way the image loading or javascript events performances (introducing a random delay).
home