8

My application is currently using HTML5 appcache.

I want to get the hash of files that I get from update() events. However, I can't seem to find out how to access the resources I downloaded.

I want to do something like

$.get( "/sunflowers.png", function( data ) {
       hash(data)
});

I know that I can view the cached resources via chrome-internals however I hope to automate this process

PS: Bump for chromium devs! please advice.

laycat
  • 5,381
  • 7
  • 31
  • 46
  • What is your end goal? You could probably use swapCache() after the update is complete and then request the files via ajax. I don't think you can get a list of the individual files that were updated from the browser. You'd had to determine the list of files on your own from the cache manifest or via another method. – Robert Harris Mar 05 '16 at 01:33
  • @RobertHarris I'm unable to access the files with ajax due to cross-origin restrictions, however I know for sure the files have been downloaded by the browser yet I'm unable to access them without chrome-internals. – laycat Mar 05 '16 at 02:22
  • 1
    Gotcha. I'm guessing you can't adjust Access-Control-Allow-Origin server side? I guess service workers won't be a viable option either then if you can't make server side changes. – Robert Harris Mar 05 '16 at 02:43
  • you can use an addon to allow it -- https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en – Tasos Mar 06 '16 at 01:21
  • @tasos that a possible method, however it will be hard to get all our users to download the add-on. Could you prove more information on how the addon is accessing AppCache data? – laycat Mar 06 '16 at 02:22
  • i dont know -- you are the one that mentioned unable to access the files with ajax due to cross-origin restrictions -- and thats one way to sort it out. have you tested it yet? as for the users, the cross-origin restrictions are usually down to your domain so if those files are coming from a single domain then you need to register a domain name and use that to get your files via ajax – Tasos Mar 06 '16 at 02:33
  • if its a CORS issue check the following sites on how to resolve it -- http://www.html5rocks.com/en/tutorials/cors/ -- http://enable-cors.org/ – Tasos Mar 06 '16 at 03:04
  • for clarification, I never solved this. This is not a CORS issue, as I have a hardcoded hash within my webapp. The goal here is to check if the files downloaded by appcache has the same hashes. The main issue for me is that there is no way to access the files downloaded by appcache; you have to trust that Appcache downloaded the right files. – laycat May 30 '16 at 08:06

1 Answers1

0

AppCache is effectively deprecated at this point, so it's not likely that the answer for this original use case would still be relevant.

But in general, it's worth pointing out that there's a more "official" way of confirming that the contents of a downloaded subresource match the expected local hashes: using subresource integrity.

Jeff Posnick
  • 53,580
  • 14
  • 141
  • 167