Prohibit browser caching

Ensure resources are not cached on the front end, while allowing caching within Fastly.

VCL

Use this solution in your VCL service (click RUN below to test this solution or clone it to make changes):

Compute@Edge

Use this solution in your Compute@Edge service:

  1. Rust
const BACKEND_NAME: &str = "httpbin.org";
#[fastly::main]
fn main(req: Request) -> Result<Response, Error> {
// Send request to backend
let mut resp = req.send(BACKEND_NAME)?;
// Cache-Control: no-store prevents browsers from writing the object to disk.
// We add 'private' in case there are any public caches downstream of Fastly,
// between us and the browser, which might perform request collapsing on public content
resp.set_header(header::CACHE_CONTROL, "private, no-store");
// Remove all other caching-related response headers
resp.remove_header(header::EXPIRES);
resp.remove_header(header::ETAG);
resp.remove_header(header::LAST_MODIFIED);
Ok(resp)
}