WEBVTT

1
00:00:01.200 --> 00:00:05.726
Load a page twice, and watch the Network panel the second time.

2
00:00:05.867 --> 00:00:08.141
Some rows don't say 200.

3
00:00:08.166 --> 00:00:10.788
They say 304.

4
00:00:10.988 --> 00:00:14.005
Three oh four means Not Modified.

5
00:00:14.088 --> 00:00:17.511
It's the request you almost skipped.

6
00:00:18.211 --> 00:00:23.457
The first time, Demo Company sent the cat photo with two extra headers.

7
00:00:23.668 --> 00:00:28.472
One said: keep a copy, but check with me before you use it.

8
00:00:28.683 --> 00:00:33.418
The other, the ETag, is a fingerprint of the file.

9
00:00:33.618 --> 00:00:38.179
The second time, the browser asks a question instead of a demand.

10
00:00:38.541 --> 00:00:41.581
If none match this fingerprint, send it.

11
00:00:41.768 --> 00:00:49.498
The file hasn't changed, so the server answers three oh four: no body, just a few hundred bytes of headers.

12
00:00:49.570 --> 00:00:52.865
Forty-two thousand bytes stay home.

13
00:00:53.066 --> 00:00:57.685
Fun fact: the older version of the question uses a date.

14
00:00:57.896 --> 00:01:01.818
Last-Modified, then If-Modified-Since.

15
00:01:01.959 --> 00:01:04.604
The fingerprint is more exact.

16
00:01:05.304 --> 00:01:08.576
Every response can say how long to keep it.

17
00:01:08.717 --> 00:01:13.685
No-store: don't keep a copy, download every time.

18
00:01:13.885 --> 00:01:19.235
Max-age zero, must-revalidate: keep it, but ask first.

19
00:01:19.318 --> 00:01:21.070
That's the three oh four.

20
00:01:21.373 --> 00:01:25.702
It still costs a round trip, but almost no bytes.

21
00:01:25.902 --> 00:01:30.509
A long max-age: keep it for a year and don't even ask.

22
00:01:30.534 --> 00:01:32.111
No request at all.

23
00:01:32.322 --> 00:01:41.063
That's only safe when the URL changes whenever the file does, so build tools put a fingerprint in the file name.

24
00:01:41.762 --> 00:01:43.838
So choose per file.

25
00:01:43.863 --> 00:01:46.776
Pages that change: ask first.

26
00:01:46.917 --> 00:01:51.547
Fingerprinted scripts, styles and images: keep for a year.

27
00:01:51.851 --> 00:01:55.622
Private or one-time answers: don't store.

28
00:01:55.823 --> 00:02:02.532
Open Demo Company's cache page, fetch each card twice, and watch all three answers happen.
