JiDW
JiDW

Reputation: 51

Detect if an image is cached

To know if an image is in the cache, you can use in Firefox mozIsLocallyAvailable(). There is no such things from chrome or IE.

Do you know any other ways ?

I tried to check for "304 not modified" with Ajax, but Ajax seems to have its own cache system. (Everytime I close the browser, the ajax cache is deleted)

My goal is to detect when my visitors cleaned their cache, so I can restart my "background preloading" system (It's for a game with a lot of images). I've heard a little about AppCache but not enough to know if it can store up to 40mb of images and if it can download them once the page is finished loading.

Regards.

Upvotes: 1

Views: 1095

Answers (2)

jgillich
jgillich

Reputation: 76219

My goal is to detect when my visitors cleaned their cache, so I can restart my "background preloading" system

You can just preload the images on every session. If the browser has them in the cache, it won't load them again. Just make sure you send the right headers.

Upvotes: 0

T.J. Crowder
T.J. Crowder

Reputation: 1074485

Given what you've stated as your end goal, I think what I'd do is have the background (pre)loading process always occur, and if it hasn't completed within (say) 250ms or 500ms, put up a message telling the user what's happening. If all 40MB of images load within a very short period of time, you can be fairly certain they're coming from cache. :-) Conversely, if they take more than 500ms (half a second) to load, you don't really care whether that's because they're being downloaded or if for some reason the user's cache is just really slow, you still probably want to tell them what's going on.

Upvotes: 1

Related Questions