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
Cache Me If You Can
Search
Maxi Ferreira
November 30, 2019
Programming
1
64
Cache Me If You Can
Lightning Talk at JSConf Japan 2019
Maxi Ferreira
November 30, 2019
Tweet
Share
Other Decks in Programming
See All in Programming
AI コーディングエージェントの時代へ:JetBrains が描く開発の未来
masaruhr
1
190
初学者でも今すぐできる、Claude Codeの生産性を10倍上げるTips
s4yuba
16
12k
dbt民主化とLLMによる開発ブースト ~ AI Readyな分析サイクルを目指して ~
yoshyum
3
1k
Modern Angular with Signals and Signal Store:New Rules for Your Architecture @enterJS Advanced Angular Day 2025
manfredsteyer
PRO
0
230
LT 2025-06-30: プロダクトエンジニアの役割
yamamotok
0
790
Team operations that are not burdened by SRE
kazatohiei
1
320
Advanced Micro Frontends: Multi Version/ Framework Scenarios @WAD 2025, Berlin
manfredsteyer
PRO
0
280
AIプログラマーDevinは PHPerの夢を見るか?
shinyasaita
1
230
Hack Claude Code with Claude Code
choplin
4
2.3k
Webの外へ飛び出せ NativePHPが切り拓くPHPの未来
takuyakatsusa
2
560
ruby.wasmで多人数リアルタイム通信ゲームを作ろう
lnit
3
490
PipeCDのプラグイン化で目指すところ
warashi
1
280
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
GitHub's CSS Performance
jonrohan
1031
460k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.7k
Making the Leap to Tech Lead
cromwellryan
134
9.4k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
18
980
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
46
9.6k
A designer walks into a library…
pauljervisheath
207
24k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.7k
A better future with KSS
kneath
238
17k
Art, The Web, and Tiny UX
lynnandtonic
299
21k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
Transcript
Maxi Ferreira JS Engineer @ Help Scout JSConf Japan !
November 30, 2019 Cache Me If You Can @charca
Cache is King
–Phil Karlton “There are only two hard things in Computer
Science: cache invalidation and naming things.”
None
Service Worker Cache
Service Worker Cache HTTP Cache
Service Worker Cache HTTP Cache Proxy Cache
Service Worker Cache HTTP Cache Proxy Cache CDN Cache
HTTP Cache & Cache-Control
Cache-Control Directives no-store no-cache max-age s-maxage immutable no-transform public private
must-revalidate proxy-revalidate stale-while-revalidate stale-if-error
Cache-Control Directives no-store no-cache max-age s-maxage immutable no-transform public private
must-revalidate proxy-revalidate stale-while-revalidate stale-if-error
Cache-Control: no-store
Cache-Control: no-store “Don’t Cache”
Cache-Control: no-store
GET /main.js Cache-Control: no-store
GET /main.js 200 OK Cache-Control: no-store Cache-Control: no-store
GET /main.js 200 OK Cache-Control: no-store Cache-Control: no-store
Cache-Control: no-store
Cache-Control: no-store ✅ Guarantees the resource is up to date
Cache-Control: no-store ✅ Guarantees the resource is up to date
❌ Downloads the full resource on every request
Cache-Control: no-cache
Cache-Control: no-cache “Don’t Cache”
Cache-Control: no-cache “Don’t Cache” “Yes Cache, but revalidate with the
server before using”
–Phil Karlton “There are only two hard things in Computer
Science: cache invalidation and naming things.”
Cache-Control: no-cache
GET /main.js Cache-Control: no-cache
GET /main.js 200 OK Cache-Control: no-cache ETag: abc123 Cache-Control: no-cache
GET /main.js 200 OK Cache-Control: no-cache ETag: abc123 main.js no-cache
abc123 Cache-Control: no-cache
GET /main.js 200 OK Cache-Control: no-cache ETag: abc123 main.js no-cache
abc123 Cache-Control: no-cache
main.js no-cache abc123 Cache-Control: no-cache
GET /main.js main.js no-cache abc123 Cache-Control: no-cache
GET /main.js main.js no-cache abc123 GET /main.js If-None-Match: abc123 Cache-Control:
no-cache
GET /main.js 304 Not Modified Cache-Control: no-cache ETag: abc123 main.js
no-cache abc123 GET /main.js If-None-Match: abc123 Cache-Control: no-cache
GET /main.js 304 Not Modified Cache-Control: no-cache ETag: abc123 main.js
no-cache abc123 GET /main.js If-None-Match: abc123 Cache-Control: no-cache
Cache-Control: no-cache
Cache-Control: no-cache ✅ Guarantees the resource is up to date
Cache-Control: no-cache ✅ Guarantees the resource is up to date
✅ Doesn’t download the resource unnecessarily
Cache-Control: no-cache ✅ Guarantees the resource is up to date
✅ Doesn’t download the resource unnecessarily ❌ Has to check with the server on every request
Cache-Control: max-age={x}
Cache-Control: max-age={x} “Keep this resource fresh in the cache for
{x} seconds.”
Fresh <-> Stale
Cache-Control: max-age
GET /main.js Cache-Control: max-age
GET /main.js 200 OK Cache-Control: max-age=100 ETag: abc123 Cache-Control: max-age
GET /main.js 200 OK Cache-Control: max-age=100 ETag: abc123 main.js max-age=100
age=0 abc123 Cache-Control: max-age
GET /main.js 200 OK Cache-Control: max-age=100 ETag: abc123 main.js max-age=100
age=0 abc123 Cache-Control: max-age
main.js max-age=100 age=20 abc123 Cache-Control: max-age
GET /main.js main.js max-age=100 age=20 abc123 Cache-Control: max-age
GET /main.js main.js max-age=100 age=20 abc123 Cache-Control: max-age
Cache-Control: max-age main.js max-age=100 age=120 abc123
GET /main.js Cache-Control: max-age main.js max-age=100 age=120 abc123
GET /main.js GET /main.js If-None-Match: abc123 Cache-Control: max-age main.js max-age=100
age=120 abc123
GET /main.js 304 Not Modified Cache-Control: max-age=100 ETag: abc123 GET
/main.js If-None-Match: abc123 Cache-Control: max-age main.js max-age=100 age=120 abc123
GET /main.js 304 Not Modified Cache-Control: max-age=100 ETag: abc123 GET
/main.js If-None-Match: abc123 Cache-Control: max-age main.js max-age=100 age=0 abc123
GET /main.js 304 Not Modified Cache-Control: max-age=100 ETag: abc123 GET
/main.js If-None-Match: abc123 Cache-Control: max-age main.js max-age=100 age=0 abc123
Cache-Control: max-age
Cache-Control: max-age ✅ Uses the resource directly from the cache
Cache-Control: max-age ✅ Uses the resource directly from the cache
✅ Doesn’t need to check with the server
Cache-Control: max-age ✅ Uses the resource directly from the cache
✅ Doesn’t need to check with the server How do we guarantee that the resource is up to date?
Cache-Control: max-age ✅ Uses the resource directly from the cache
✅ Doesn’t need to check with the server How do we guarantee that the resource is up to date? max-age=???
max-age=0
max-age=600
max-age=until-it-changes
Immutable Resources + Aggressive Caching
max-age=31536000
Revision Stamping main.js vendors.js styles.css
Revision Stamping main.js vendors.js styles.css
Revision Stamping main.js vendors.js styles.css main.ee8f28.js vendors.ab2f18.js styles.f74ee2.css
Cache-Control: max-age
GET /main.abc.js Cache-Control: max-age
GET /main.abc.js 200 OK Cache-Control: max-age=31536000 ETag: abc123 Cache-Control: max-age
GET /main.abc.js 200 OK Cache-Control: max-age=31536000 ETag: abc123 main.abc.js max-age=
31536000 age=0 abc123 Cache-Control: max-age
GET /main.abc.js 200 OK Cache-Control: max-age=31536000 ETag: abc123 main.abc.js max-age=
31536000 age=0 abc123 Cache-Control: max-age
main.abc.js max-age= 31536000 age=3600 abc123 Cache-Control: max-age
GET /main.abc.js main.abc.js max-age= 31536000 age=3600 abc123 Cache-Control: max-age
GET /main.abc.js main.abc.js max-age= 31536000 age=3600 abc123 Cache-Control: max-age
Cache-Control: max-age main.abc.js max-age= 31536000 age=7200 abc123
GET /main.def.js Cache-Control: max-age main.abc.js max-age= 31536000 age=7200 abc123
GET /main.def.js 200 OK Cache-Control: max-age=31536000 ETag: def456 Cache-Control: max-age
main.abc.js max-age= 31536000 age=7200 abc123
GET /main.def.js 200 OK Cache-Control: max-age=31536000 ETag: def456 Cache-Control: max-age
main.abc.js max-age= 31536000 age=7200 abc123
GET /main.def.js 200 OK Cache-Control: max-age=31536000 ETag: def456 Cache-Control: max-age
main.def.js max-age= 31536000 age=0 def456 main.abc.js max-age= 31536000 age=7200 abc123
GET /main.def.js 200 OK Cache-Control: max-age=31536000 ETag: def456 Cache-Control: max-age
main.def.js max-age= 31536000 age=0 def456 main.abc.js max-age= 31536000 age=7200 abc123
Cache-Control: max-age=31536000 + Revision Stamping
Cache-Control: max-age=31536000 + Revision Stamping ✅ Uses the resource directly
from the cache
Cache-Control: max-age=31536000 + Revision Stamping ✅ Uses the resource directly
from the cache ✅ Doesn’t need to check with the server
Cache-Control: max-age=31536000 + Revision Stamping ✅ Uses the resource directly
from the cache ✅ Doesn’t need to check with the server ✅ Guarantees the resource is up to date
Final Notes
Final Notes Use the cache to prevent roundtrips to the
server.
Final Notes Use the cache to prevent roundtrips to the
server. Whenever possible, use immutable resources with caches that don’t expire
Final Notes Use the cache to prevent roundtrips to the
server. Whenever possible, use immutable resources with caches that don’t expire Check the docs of your CDNs
Final Notes Use the cache to prevent roundtrips to the
server. Whenever possible, use immutable resources with caches that don’t expire Check the docs of your CDNs If you need more flexibility, use a Service Worker
Thank you