3

I know that when the server returns 304 NOT MODIFIED, the browser handles it transparently and there's no way for any client code to make direct use of it. My problem is that the list is really huge (>4 MB uncompressed) and converting it to JSON takes quite long (70 ms on my desktop, much longer on Android where it matters).

I don't want to use angularjs cache here, as the HTTP request must be done. I don't want to work with partial lists.

I guess using the E-Tag header and hacking into defaultHttpResponseTransform would help, but I wonder if there's a standard way of avoiding this overhead.

Community
  • 1
  • 1
maaartinus
  • 44,714
  • 32
  • 161
  • 320

1 Answers1

1

You can combine $cache with browser cache simply by comparing the E-tag in the header in your code. You can't catch 304 status as the browser simulates 200 status code always. There is library that handles this kind of problem https://www.npmjs.com/package/angular-http-etag. But the problem with parsing json you can't avoid because localStorage also serializes json into string so you will have to parse it ether way. My suggestion is to split the json into smaller chunks and request it as needed

Kliment
  • 2,250
  • 3
  • 18
  • 32
  • Sounds good! And I *can* avoid serialization as I have to check the same data rather often and plan to use a non-persistent cache (just a plain js object). Actually, `localStorage` is too limited (5 MB or so). Splitting is currently not an option. – maaartinus Nov 22 '16 at 12:26
  • You can try using service worker https://mobiforge.com/design-development/taking-web-offline-service-workers. The limit in MB is 50. Also if you can't split the file try to compress it. Json files are very compressible. You can split the size of the file in half just by compressing it with tar.gz. https://www.npmjs.com/package/tar.gz. Also try to find repeatable data in the file and compress it manually by keeping only one copy of that string and using references of that string to replace it in the file – Kliment Nov 22 '16 at 12:39