-
Notifications
You must be signed in to change notification settings - Fork 888
feat: add caching headers for Next.js static assets #330
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
Conversation
Codecov Report
@@ Coverage Diff @@
## main #330 +/- ##
==========================================
+ Coverage 63.61% 67.66% +4.05%
==========================================
Files 69 140 +71
Lines 786 7425 +6639
Branches 77 77
==========================================
+ Hits 500 5024 +4524
- Misses 271 1893 +1622
- Partials 15 508 +493
Continue to review full report at Codecov.
|
if strings.HasPrefix(request.URL.Path, "/_next/static/") { | ||
writer.Header().Add("Cache-Control", "public, max-age=31536000, immutable") | ||
} |
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.
Looks great! Thanks for bringing this over @jawnsy 👍
res, err := request(server, "/index.html") | ||
require.NoError(t, err) | ||
require.NoError(t, res.Body.Close()) |
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.
Nice tests 👍
Default page has no caching:
Immutable cache-control for Next.js assets:
API calls not cached:
Other static content outside
_next/static
not cached: