简体   繁体   中英

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.

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM