Cache Control in JavaScript
From the Fetch API cheat sheet · Request Configuration · verified Jul 2026
Cache Control
Managing request caching and cache strategies
javascript
// Cache modes
await fetch(url, {
cache: 'default' // Browser decides
})
await fetch(url, {
cache: 'no-cache' // Validate with server
})
await fetch(url, {
cache: 'reload' // Bypass cache completely
})
await fetch(url, {
cache: 'force-cache' // Use cache if available
})
await fetch(url, {
cache: 'only-if-cached' // Cache only, fail otherwise
})
// Cache with headers
const response = await fetch(url, {
cache: 'no-cache',
headers: {
'Cache-Control': 'no-cache',
'Pragma': 'no-cache'
}
})
// Conditional requests
const response = await fetch(url, {
headers: {
'If-Modified-Since': lastModified,
'If-None-Match': etag
}
})
if (response.status === 304) {
console.log('Not modified, use cached version')
}⚡ force-cache improves performance for static resources
💡 no-cache still uses cache but validates first
📌 ETags enable efficient conditional requests
🟢 Service Workers provide powerful offline caching