Skip to content

feat: override "cache-control" header and set to "no-cache" for 404s

Gonzalo Servat requested to merge stop-caching-404s into master

Why is this change being made?

When hitting about.gitlab.com with a non-existent page, Google is returning the cache headers of the 404.html file, which are set to public and max-age: 14400. This could lead to browsers caching 404s.

This MR overrides the Cache-Control header to set to no-cache.

Requested in https://gitlab.com/gitlab-com/marketing/digital-experience/gitlab-blog/-/issues/87#note_1733157987.

BEFORE

< HTTP/1.1 404 Not Found
< date: Tue, 23 Jan 2024 23:59:37 GMT
< content-type: text/html
< cf-ray: 84a3fdcefea94874-BNE
< cf-cache-status: EXPIRED
< cache-control: public, max-age=14400       <<<<<
< expires: Wed, 24 Jan 2024 03:59:37 GMT
< last-modified: Tue, 23 Jan 2024 23:49:51 GMT
< vary: Accept-Encoding, Origin
< x-goog-generation: 1706053791195286
< x-goog-hash: crc32c=ScLFAg==, md5=tPD7pNxTaM9FkXx1nMMZhA==
< x-goog-meta-goog-reserved-file-mtime: 1706053136
< x-goog-metageneration: 1
< x-goog-storage-class: MULTI_REGIONAL
< x-goog-stored-content-encoding: gzip
< x-goog-stored-content-length: 3281
< x-guploader-uploadid: ABPtcPqfKWQmNhs37GehUco3syN8N3m8DPrPUA5Z3XIwmY9CcbS8XEyXkQxxSWaNbKc2tG58D6I
< server: cloudflare
< Connection: keep-alive
< Keep-Alive: timeout=5
< Transfer-Encoding: chunked

AFTER

< HTTP/1.1 404 Not Found
< date: Wed, 24 Jan 2024 00:07:45 GMT
< content-type: text/html
< cf-ray: 84a409b6ad6d487a-BNE
< cf-cache-status: MISS
< cache-control: no-cache  <<<<< (... and "Expires" header removed)
< last-modified: Wed, 24 Jan 2024 00:07:33 GMT
< vary: Accept-Encoding, Origin
< x-goog-generation: 1706054853367489
< x-goog-hash: crc32c=eLf3xQ==, md5=isuWd/8j2gJGHMzu9hXiMw==
< x-goog-meta-goog-reserved-file-mtime: 1706053317
< x-goog-metageneration: 1
< x-goog-storage-class: MULTI_REGIONAL
< x-goog-stored-content-encoding: gzip
< x-goog-stored-content-length: 3281
< x-guploader-uploadid: ABPtcPp-N5ebhxdO8uL_XOZBGmfqkeBnwZXAQxD36wPQ1_4VAMtnHzys6-nRyMObJ64zhzH7Zp-9hsaLnQ
< server: cloudflare
< Connection: keep-alive
< Keep-Alive: timeout=5
< Transfer-Encoding: chunked

Author and Reviewer Checklist

Please verify the check list and ensure to tick them off before the MR is merged.

  • Provided a concise title for this Merge Request (MR)
  • Added a description to this MR explaining the reasons for the proposed change, per say why, not just what
    • Copy/paste the Slack conversation to document it for later, or upload screenshots. Verify that no confidential data is added, and the content is SAFE
  • Assign reviewers for this MR to the correct Directly Responsible Individual/s (DRI)
    • If the DRI for the page/s being updated isn’t immediately clear, then assign it to one of the people listed in the Maintained by section on the page being edited
    • If your manager does not have merge rights, please ask someone to merge it AFTER it has been approved by your manager in #mr-buddies
    • The when to get approval handbook section explains the workflow in more detail
  • For transparency, share this MR with the audience that will be impacted.
    • Team: For changes that affect your direct team, share in your group Slack channel
    • Department: If the update affects your department, share the MR in your department Slack channel
    • Company: If the update affects all (or the majority of) GitLab team members, post an update in #whats-happening-at-gitlab linking to this MR

Edited by Gonzalo Servat

Merge request reports