Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
HTTP + Caching - PHPUG Cologne 2014/03
Search
Tobias Gies
March 07, 2014
Programming
1
130
HTTP + Caching - PHPUG Cologne 2014/03
A talk about HTTP headers and how they influence cache behavior.
Tobias Gies
March 07, 2014
Tweet
Share
More Decks by Tobias Gies
See All by Tobias Gies
Intro to Apache Kafka #phpbnl20
tobiasgies
1
300
Technical Debt - #phpbnl16
tobiasgies
1
210
Technical Debt: Why it's crippling you and what to do
tobiasgies
0
180
Action-Domain-Responder - PHPNW14
tobiasgies
1
600
Dependency Injection - PHPUG Cologne 2013/8
tobiasgies
1
180
Dependency Injection
tobiasgies
1
140
Other Decks in Programming
See All in Programming
rails newと同時に型を書く
aki19035vc
6
740
Flatt Security XSS Challenge 解答・解説
flatt_security
0
800
振り返れば奴(Cline)がいる
keiyagi
0
110
Rubyでつくるパケットキャプチャツール
ydah
0
420
ゼロからの、レトロゲームエンジンの作り方
tokujiros
3
1.1k
AHC041解説
terryu16
0
520
BEエンジニアがFEの業務をできるようになるまでにやったこと
yoshida_ryushin
0
250
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
6
1.5k
最近のVS Codeで気になるニュース 2025/01
74th
1
230
2024年のkintone API振り返りと2025年 / kintone API look back in 2024
tasshi
0
160
Vue.jsでiOSアプリを作る方法
hal_spidernight
0
120
ファインディの テックブログ爆誕までの軌跡
starfish719
1
700
Featured
See All Featured
KATA
mclloyd
29
14k
Documentation Writing (for coders)
carmenintech
67
4.6k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Navigating Team Friction
lara
183
15k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
590
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Practical Orchestrator
shlominoach
186
10k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3.1k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7.1k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
6
210
Transcript
HTTP
HyperText Transfer Protocol
HTTP request GET /index.1.de.html HTTP/1.1 Host: www.example.com
HTTP request GET / HTTP/1.1 Host: www.example.com Connection: keep-alive Cache-Control:
no-cache Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Pragma: no-cache User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36 Accept-Encoding: gzip,deflate,sdch Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4 Cookie: sid=t73fuqi322d115fdr8tt1fsf30
HTTP response HTTP/1.1 200 OK Date: Thu, 20 Feb 2014
14:42:03 GMT Server: Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.9 mod_ssl/2.2.22 OpenSSL/1.0.1 X-Powered-By: PHP/5.3.10-1ubuntu3.9 P3P: CP="NOI NID ADMa OUR IND UNI COM NAV" Set-Cookie: sid=t73fuqi322d115fdr8tt1fsf30; path=/; HttpOnly Expires: Sun, 22 Dec 2013 14:42:03 GMT Cache-Control: no-store, no-cache, must-revalidate, no-transform Last-Modified: Thu, 20 Feb 2014 14:42:03 GMT X-Generator: papaya CMS X-Papaya-Cache: no Content-Encoding: gzip X-Papaya-Gzip: yes Content-Length: 6315 Keep-Alive: timeout=5, max=95 Connection: Keep-Alive Content-Type: text/html; charset=utf-8
HTTP-Methoden • GET • POST • PUT • DELETE •
HEAD
HTTP status codes
Exkurs: Caches
Cache-Arten • Browser-Cache • Proxy Cache • Gateway Cache /
Reverse Proxy – Self-hosted (Varnish, …) – Kommerziell / CDN (Cloudflare, Akamai & co.)
Cache-relevante HTTP-Header • Expires • Cache-Control • ETag • Last-Modified
• If-Modified-Since • If-None-Match • Vary • Age • Set-Cookie
Expires Expires: Sun, 22 Dec 2013 14:42:03 GMT • HTTP/1.0
• Ablaufdatum des Inhalts (Zeitzone GMT!) • Nützlich für Caching statischer Ressourcen
Cache-Control Cache-Control: no-cache, must-revalidate • HTTP/1.1 • Wesentlich feinere Kontrolle
über den Cache • Optionen: – max-age – s-maxage – public – private
Cache-Control Cache-Control: no-cache, must-revalidate • HTTP/1.1 • Wesentlich feinere Kontrolle
über den Cache • Optionen (2): – no-cache – no-store – must-revalidate – proxy-revalidate
ETag ETag: [W/]"some-random-value" • HTTP/1.1 • Identifiziert eine Version einer
Ressource eindeutig • Starker ETag: Garantiert identische Ressource • Schwacher ETag (W/): Garantiert äquivalente Ressource • Bei statischen Ressourcen abschalten
Last-Modified Last-Modified: Thu, 20 Feb 2014 14:42:03 GMT • Letztes
Änderungsdatum der Ressource
If-Modified-Since If-Modified-Since: Wed, 01 Sep 2004 13:24:52 GMT • Request-Header
• Nur ausliefern, wenn neuere Version vorhanden • Sonst Status 304
If-None-Match If-None-Match: "some-random-value" • Request-Header • Abfrage, ob Version mit
diesem ETag vorhanden • Wenn ja: Status 304
Vary Vary: Cookie,Accept,Accept-Encoding • Information an Caches: Antwort unterscheidet sich
je nach Wert der angegebenen Request- Header! • Bspw. wichtig im Umgang mit schlecht konfigurierten Corporate Proxies
Age Age: 30 • Gibt das Alter der Ressource in
Sekunden an • Caches rechnen: request timestamp – now – Age + max-age > 0? • Wird auch von Caches selbst angegeben
Set-Cookie Set-Cookie: name=somevalue; Secure • Inhalt, der Cookies enthält, ist
uncached! • Aber: Cookies sind nützlich, um mehrere Versionen einer Ressource im Reverse-Proxy zu cachen.
POST • POST bedeutet: Es wird eine Ressource verändert. •
Antworten auf POST-Requests werden nicht gecached. • POST also nur da verwenden, wo es nötig ist.
Ressourcen • Wikipedia: „Liste der HTTP-Headerfelder“ • Caching Tutorial for
web authors and webmasters: http://www.mnot.net/cache_docs/ • HTTP – The Varnish Cookbook: https://www.varnish-software.com/static/book/HTTP.html • YSlow: Best practices for speeding up your website: http://developer.yahoo.com/performance/rules.html
Noch Fragen?