Skip to content

Commit 115d4d2

Browse files
committed
Add content to http caching
1 parent d6fba2c commit 115d4d2

File tree

4 files changed

+119
-7
lines changed

4 files changed

+119
-7
lines changed

apps/components_guide_web/assets/css/app.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ a {
4949
text-decoration: var(--link-decoration);
5050
}
5151
a:hover {
52-
text-decoration: var(--hover\: links-decoration);
52+
text-decoration: var(--hover\:links-decoration);
5353
}
5454

5555
h1,

apps/components_guide_web/lib/components_guide_web/controllers/research_controller.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ defmodule ComponentsGuideWeb.ResearchController do
137137
}
138138
) do
139139
Section.card([
140+
# inspect(item),
140141
content_tag(:h3, title, class: "text-2xl"),
141142
content_tag(
142143
:dl,
Lines changed: 116 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,122 @@
11
# HTTP Caching
22

3-
## Initial response
3+
## Resource that does not want to be cached
44

5-
## When server has same etag
5+
```http
6+
GET /about HTTP/1.1
7+
HOST: example.org
8+
```
69

7-
## When server has not been modified since
10+
```http
11+
HTTP/1.1 200 OK
12+
Cache-Control: max-age=0, private, must-revalidate
13+
Date: Fri, 02 Oct 2020 09:28:50 GMT
14+
Content-Type: text/html; charset=utf-8
15+
Content-Length: 4321
16+
```
817

9-
## When server has different etag
18+
## Resource that wants to be cached
1019

11-
## When server has been modified since
20+
```http
21+
GET /assets/logo.png HTTP/1.1
22+
Host: example.org
23+
```
24+
25+
```http
26+
HTTP/1.1 200 OK
27+
ETag: "ABC"
28+
Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT
29+
Cache-Control: public, max-age=31536000
30+
Date: Fri, 02 Oct 2020 09:28:50 GMT
31+
Content-Type: image/png
32+
Content-Length: 2348
33+
Vary: Accept-Encoding
34+
35+
… data …
36+
```
37+
38+
### When server has same etag
39+
40+
```http
41+
GET /assets/logo.png HTTP/1.1
42+
Host: example.org
43+
If-None-Match: "ABC"
44+
```
45+
46+
```http
47+
HTTP/1.1 304 Not Modified
48+
ETag: "ABC"
49+
Date: Fri, 02 Oct 2020 09:28:50 GMT
50+
Content-Type: image/png
51+
Content-Length: 2348
52+
Cache-Control: public, max-age=31536000
53+
Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT
54+
Vary: Accept-Encoding
55+
56+
```
57+
58+
### When server has not been modified since
59+
60+
```http
61+
GET /assets/logo.png HTTP/1.1
62+
Host: example.org
63+
If-Modified-Since: Wed, 21 Oct 2015 07:28:00 GMT
64+
```
65+
66+
```http
67+
HTTP/1.1 304 Not Modified
68+
Date: Fri, 02 Oct 2020 09:28:50 GMT
69+
Content-Type: image/png
70+
Content-Length: 2348
71+
Cache-Control: public, max-age=31536000
72+
ETag: "ABC"
73+
Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT
74+
Vary: Accept-Encoding
75+
76+
```
77+
78+
### When server does not have that etag
79+
80+
```http
81+
GET /assets/logo.png HTTP/1.1
82+
Host: example.org
83+
If-None-Match: "ABC"
84+
```
85+
86+
```http
87+
HTTP/1.1 200 OK
88+
ETag: "XYZ"
89+
Date: Fri, 02 Oct 2020 09:28:50 GMT
90+
Content-Type: image/png
91+
Content-Length: 2348
92+
Cache-Control: public, max-age=31536000
93+
Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT
94+
Vary: Accept-Encoding
95+
96+
```
97+
98+
### When server has been modified since
99+
100+
```http
101+
GET /assets/logo.png HTTP/1.1
102+
Host: example.org
103+
If-Modified-Since: Wed, 21 Oct 2015 07:28:00 GMT
104+
```
105+
106+
```http
107+
HTTP/1.1 200 OK
108+
ETag: "XYZ"
109+
Date: Fri, 02 Oct 2020 09:28:50 GMT
110+
Content-Type: image/png
111+
Content-Length: 2348
112+
Cache-Control: public, max-age=31536000
113+
Last-Modified: Thu, 22 Oct 2015 07:28:00 GMT
114+
Vary: Accept-Encoding
115+
116+
```
117+
118+
## See more
119+
120+
- [MDN: HTTP caching](https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching)
121+
- [MDN: If-None-Match](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match)
122+
- [MDN: 412 Precondition Failed](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/412)

apps/components_guide_web/lib/components_guide_web/templates/web/index.html.eex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<article>
44
<div class="text-white bg-gray-900">
5-
<div class="content max-w-4xl mx-auto py-8 text-xl">
5+
<div class="content max-w-4xl mx-auto py-8 text-xl" style="--link-decoration: underline;">
66
<%= render(@view_module, @article <> ".html", conn: @conn) %>
77
</div>
88
</div>

0 commit comments

Comments
 (0)