views:

1676

answers:

5

Hi, I'm trying to load an image from the Firefox cache as the title suggests. I'm running Ubuntu, so the location of my cache is /home/me/.mozilla/firefox/xxxxxx.default/Cache

However, in the Cache (and this is on Mac, too) the filenames are just ridiculous combinations of letters and numbers. Is there a way to pinpoint a certain file?

A: 

What are you trying to load this image from? Are you trying to make a FF extension?

Are you using C, or Java, or Python...?

Are you simply trying to do this by double-clicking the file?

stalepretzel
A: 

Greasemonkey extension. I created an img element using document.createElement('img') and now I want to load a particular image from the cache into it.

Sorry for not saying before, didn't think it mattered...

Put this clarification in your question, not as an answer.
derobert
+1  A: 

Ummm, that really is an internal implementation detail. But I suggest looking at how about:cache?device=disk and about:cache-entry?client=HTTP&sb=1&key=http://stackoverflow.com/Content/img/wmd/blockquote.png are implemented.

Also, http://www.securityfocus.com/infocus/1832 gives details, too. Note that Firefox doesn't use a separate file for everything...

And of course, Firefox may change the format at any time.

derobert
+2  A: 

You should take a look at the source code of the CacheViewer Add-on.
Download the file instead of installing it (right click and save as) and then extract it (it's just a Zip file, even though it has a .xpi extension), then extract the cacheviewer.jar file inside the resulting chrome folder. Finally go into content and then cacheviewer to find the javascript and XUL files.

From my brief investigation, the useful routines are in the cacheviewer.js file, though if you were hoping there would be a simple javascript one liner for accessing cached items you're probably going to be disappointed. The XUL files (which are just XML) are helpful in working out which JS functions are called to perform particular tasks. I'm not too sure how all this maps into Greasemonkey, rather than the extension environment, but hopefully there's enough code to get you started.

robertc
A: 

Just give your img src= attribute the full URL. If the image happens to be cacheable (the server sends an appropriate Expires: or Cache-control: header, for example) and it's already in the cache, Firefox will not hit the network.

HTTP caching is supposed to be invisible. When you're generating content, you generally shouldn't worry about it.

You can point REDbot at a URL to see all sorts of delicious information about its cacheability.

Jason Orendorff