maaartinus
maaartinus

Reputation: 46492

Efficiently working with a 304 response status code in angular

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.

Upvotes: 3

Views: 4309

Answers (1)

Kliment
Kliment

Reputation: 2270

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

Upvotes: 1

Related Questions