Mindaugas
Mindaugas

Reputation: 1183

javascript/jquery - recognize loaded from cache

I have image gallery and am updating front-end, is there a way to use javascript or jquery or any other front end technology to identify which image was loaded from cache? I would like to apply additional class for those items.

Thanks for any sugestions.

Upvotes: 1

Views: 47

Answers (2)

Remy Grandin
Remy Grandin

Reputation: 1686

Short answer :

No

Long answer :

No, and there is a reason for that : If you could know which element of tha page was from the cache, you could deduce that your user have been to the same page or another page with the same element/ressource. It would be a massive potential privacy breach.

A similar problem was arised with the changing color of link if they are visited (see http://dbaron.org/mozilla/visited-privacy for more info)

Upvotes: 3

Özgür Kaplan
Özgür Kaplan

Reputation: 2136

You can use the function below. However it will load the image if not cached.

function isCached(src) {
    var image = new Image();
    image.src = src;
    return image.complete;
}

Upvotes: 1

Related Questions