1

Let's say an UA has requested my 800kB amalgamated source code file, and cached it. Let's say I then added a new function to that file.

How can I have the UA fetch only the added function, and update its cache, using standard HTTP headers? I explicitly don't want the UA to re-download the full 800kB.

SoniEx2
  • 1,864
  • 3
  • 27
  • 40

1 Answers1

1

If both the server and the UA are under your control, you can implement RFC 3229, which defines a protocol for this. See Section 10.7.3 for examples. However, be advised that RFC 3229 and RFC 7234 (on which it is based) are complex specifications that are easy to get wrong.

If you wish to interoperate with common UAs (which don’t implement RFC 3229), there’s no direct way to do what you want. You can emulate this by hand, though. For example, if the “source code file” in question is a JavaScript file for <script src>, then instead of changing that file, you could add another <script src> just for your new function. If you anticipate changes like this happening often, you could have two <script src> from the start: one for a large, infrequently updated base, the other for frequent small additions. See also another recent question about this: A solution idea for incremental updates using browser cache

Also consider other ways to reduce network traffic. Compress with the new Brotli algorithm, increasingly supported by Web browsers, which saves slightly more than gzip. If you’re concerned about spikes of bandwidth usage on the server side, try rolling out updates to users incrementally, so they don’t all try to fetch the entire file at the same time.

Community
  • 1
  • 1
Vasiliy Faronov
  • 11,840
  • 2
  • 38
  • 49
  • Luckily I don't need to support browsers ("common user agents") and can refuse connections if they don't implement RFC 3229. Can you tell me more about it? – SoniEx2 May 12 '18 at 14:23
  • @SoniEx2 Do I understand correctly that you are building your own server and user agent, and are just looking for a standard to avoid reinventing the protocol? What about the cache: are you also implementing [RFC 7234](https://tools.ietf.org/html/rfc7234) on your own? – Vasiliy Faronov May 12 '18 at 16:18
  • I'll probably have to build my own stuff, I guess. It's better to use a standard as doing so increases compatibility (in theory). But yeah, just doing yet another HTTP implementation :) – SoniEx2 May 13 '18 at 02:33
  • @SoniEx2 Well, I guess you could use RFC 3229 then. Read it for examples. You can check if the UA supports it by looking for the `A-IM` request header. However, I’d question if you really want this. RFC 7234 is general and complex, more so with RFC 3229. At least try to reuse an existing open-source RFC 7234 implementation for your platform. – Vasiliy Faronov May 13 '18 at 12:47
  • Could you edit your answer to remove the first statement ("You can't"), so I can accept it as the answer? – SoniEx2 Jun 02 '18 at 14:38