1

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.

JiDW
  • 51
  • 5
  • *"I tried to check for "304 not modified" with Ajax, but Ajax seems to have its own cache system."* No, it's the same one, but you don't see 304 codes. If the server replies with a 304, what *you* see (e.g., on your `XMLHttpRequest` object's `status` property) is a 200. E.g., the ajax layer hides the details from you. – T.J. Crowder Apr 10 '13 at 17:11
  • You can't really build anything cross browser that will provide reliable information about what has been cached and what hasn't. – mzedeler Apr 10 '13 at 17:13
  • I can see "304 not modified" by checking status on the "oncomplete" event. But when I do so, after cleaning my cache, I get "200" for the first call, then 304 for any call after this one. But, if I close my browser and reopen, I get another "200" before seeing "304". Like if the cache was cleaned at browser restart. – JiDW Apr 10 '13 at 22:00

2 Answers2

1

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.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • I thought about this, and may go this way, but I'd like if possible a more consistent method that doesn't rely on bandwidth speed. Thanks for the idea anyway ! – JiDW Apr 10 '13 at 22:07
  • @JiDW: My point is that it *is* consistent. :-) Presumably, your goal in showing the user the message is to let them know why there's a delay. So you don't care what the delay is, if the process continues for more than a brief moment (for whatever reason), you show the message. (Separately: I'm not following you on bandwidth, my suggestion doesn't rely on the user's connection speed.) – T.J. Crowder Apr 11 '13 at 07:46
  • Well, sorry, I got lost in my mind and forgot to explain a bit more. I already have a visible preloader for my pages, it load only images I need for this particular page. The idea is to continue to preload images after the end of this visible preloader, to speed up the future loading of other pages.So I could monitor the loading time of an image to check if his cache has been cleaned. – JiDW Apr 11 '13 at 10:42
0

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.

jgillich
  • 71,459
  • 6
  • 57
  • 85
  • It will still call HTTP Request, won't it ? I don't want to make ~250 useless HTTP request for every visitor everytime they visit the game. – JiDW Apr 10 '13 at 22:01