-
Notifications
You must be signed in to change notification settings - Fork 12
feat: enhance caching strategy for static files in Astro directory #78
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -51,24 +51,53 @@ | |||||
| OnPrepareResponse = ctx => | ||||||
| { | ||||||
| var headers = ctx.Context.Response.Headers; | ||||||
| var name = ctx.File.Name.ToLowerInvariant(); | ||||||
|
|
||||||
| // Anything served from the /_astro/ directory can be cached forever | ||||||
| // https://starlight.astro.build/environmental-impact/#caching | ||||||
| if (IsInAstroDirectory(ctx.File.PhysicalPath)) | ||||||
| { | ||||||
| headers.CacheControl = "public, max-age=604800, immutable"; | ||||||
|
||||||
| headers.CacheControl = "public, max-age=604800, immutable"; | |
| headers.CacheControl = "public, max-age=31536000, immutable"; |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cache duration for static assets has been reduced from 1 year (31536000 seconds) to 1 week (604800 seconds). For content-hashed assets (CSS, JS files) that Astro generates, a longer cache duration (1 year) is recommended and safe since the content hash in the filename ensures cache busting when content changes. Consider using different cache durations: 1 year for hashed assets (CSS, JS) and 1 week for other static assets (images, fonts).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation link references "environmental-impact" which seems unrelated to caching strategy. Consider updating to a more relevant documentation link about Astro's asset handling and caching best practices, or remove the link if it's not accurate.