Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Cache Control #6874

Merged
merged 16 commits into from
Feb 6, 2025
Merged

Update Cache Control #6874

merged 16 commits into from
Feb 6, 2025

Conversation

JKarlavige
Copy link
Collaborator

@JKarlavige JKarlavige commented Feb 5, 2025

What are you changing in this pull request and why?

This is an effort to improve caching of our docs site to reduce Vercel overages. The strategy here is to cache all images to the browser for up to 31 days. This should reduce network requests on images, thus reducing our Fast Data Transfer and Edge Requests overages.

One thing i'm not 100% clear on is whether retrieving an item from the CDN cache counts towards our Fast Data Transfer. I believe it does, as I see the Request Header x-vercel-cache: HIT consistently across network requests and we are still going over our limit.

CDN requests count towards Edge Requests. And assets loaded from the CDN (such as images), count towards Edge Requests (docs here). So this should be able to help with both overages potentially.
image

Cache settings

Images: Cache images in browser for 31 days, on CDN for 7 days.
Everything else: Cache everything else on CDN for 1 day, & don't cache on the browser.

Preview

This page has a good amount of images to verify the cache:
https://docs-getdbt-com-git-update-cache-headers-dbt-labs.vercel.app/reference/node-selection/test-selection-examples

In the network tab, reload the page and verify images are now being cached by the browser. You may have to select the Disable cache option within the network tab.
image

Select an image in the network tab, and verify the Cache-Control matches what is set in the vercel.json within this PR.

Verify that other file types such as css, js, etc. use the fallback Cache-Control of max-age=0, s-maxage=86400 stale-while-revalidate, which caches the item in Vercel's CDN for 1 day.

Notes

I will give the docs team a heads up when replacing images, the new image should have a unique name. If we ever need to bust the browser image cache, we can use the existing image-cache-wrapper. We can update the CACHE_VERSION to 3.

Note on the CDN cache - New Vercel deployments invalidate the CDN cache (see docs here), so it should be safe to cache everything on the CDN without seeing stale content after updates.


🚀 Deployment available! Here are the direct links to the updated files:

TODO

  • Remove test content before merge
  • Revert image before merge

Copy link

vercel bot commented Feb 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
docs-getdbt-com ✅ Ready (Inspect) Visit Preview Feb 6, 2025 4:46pm

@github-actions github-actions bot added the size: medium This change will take up to a week to address label Feb 5, 2025
Copy link

vercel bot commented Feb 5, 2025

Deployment failed with the following error:

Header at index 1 has invalid `source` pattern "/*.(jpg|png|svg|gif|webp)".

Learn More: https://vercel.link/invalid-route-source-pattern

Copy link

vercel bot commented Feb 5, 2025

Deployment failed with the following error:

The `vercel.json` schema validation failed with the following message: `headers[1].headers[0]` should NOT have additional property `_comment`

Learn More: https://vercel.com/docs/concepts/projects/project-configuration

Copy link

vercel bot commented Feb 5, 2025

Deployment failed with the following error:

The `vercel.json` schema validation failed with the following message: `headers[0].headers[0]` should NOT have additional property `_comment`

Learn More: https://vercel.com/docs/concepts/projects/project-configuration

Copy link

vercel bot commented Feb 5, 2025

Deployment failed with the following error:

Could not parse File as JSON: website/vercel.json

@JKarlavige JKarlavige marked this pull request as ready for review February 6, 2025 15:23
@JKarlavige JKarlavige requested a review from a team as a code owner February 6, 2025 15:23
Copy link
Member

@breezyfasano breezyfasano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! verified all images loaded from the memory cache, and did not when 'Disable cache' was disabled woo. Hoping this helps with the overages

@JKarlavige JKarlavige enabled auto-merge February 6, 2025 16:43
@JKarlavige JKarlavige merged commit 67803a6 into current Feb 6, 2025
7 checks passed
@JKarlavige JKarlavige deleted the update-cache-headers branch February 6, 2025 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: medium This change will take up to a week to address
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants