1

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.

1

2 Answers 2

3

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)

Sign up to request clarification or add additional context in comments.

4 Comments

Well Özgur's answer shows that this privacy breach does nonetheless exist.
No, the image.complete only said if the image have finished loading, it does not tell if the image was loaded from cache or from a remote server
As javascript is not multithreaded, there is a good chance that if image.complete is true immediatly after setting the src attribute, the image was loaded from the cache.
That said, I haven't checked that the code actually works.
1

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;
}

2 Comments

This will only tell of the image is loaded, not if it is loaded from cache
@RemyGrandin You are right. But if image.complete is true after setting src it's most likely was loaded from the cache.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.