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

feat: add caching headers for Next.js static assets #330

Merged
merged 1 commit into from
Feb 19, 2022

Conversation

jawnsy
Copy link
Contributor

@jawnsy jawnsy commented Feb 19, 2022

Default page has no caching:

image

Immutable cache-control for Next.js assets:

image

API calls not cached:

image

Other static content outside _next/static not cached:

image

@codecov
Copy link

codecov bot commented Feb 19, 2022

Codecov Report

Merging #330 (d5d9052) into main (5ef59e7) will increase coverage by 4.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittest-go-macos-latest 66.34% <100.00%> (?)
unittest-go-ubuntu-latest 67.69% <100.00%> (?)
unittest-go-windows-latest 65.92% <100.00%> (?)
unittest-js 63.61% <ø> (ø)
Impacted Files Coverage Δ
site/nextrouter/nextrouter.go 81.52% <100.00%> (ø)
database/postgres/postgres.go 70.73% <0.00%> (ø)
coderd/coderdtest/coderdtest.go 100.00% <0.00%> (ø)
httpmw/organizationparam.go 69.81% <0.00%> (ø)
pty/start_windows.go 52.25% <0.00%> (ø)
pty/pty.go 0.00% <0.00%> (ø)
site/embed.go 83.14% <0.00%> (ø)
codersdk/projectimport.go 64.40% <0.00%> (ø)
httpmw/userparam.go 76.66% <0.00%> (ø)
peerbroker/listen.go 84.80% <0.00%> (ø)
... and 62 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ef59e7...d5d9052. Read the comment docs.

@jawnsy jawnsy self-assigned this Feb 19, 2022
@jawnsy jawnsy marked this pull request as ready for review February 19, 2022 03:02
Comment on lines +81 to +83
if strings.HasPrefix(request.URL.Path, "/_next/static/") {
writer.Header().Add("Cache-Control", "public, max-age=31536000, immutable")
}
Copy link
Contributor

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 👍

Comment on lines +400 to +402
res, err := request(server, "/index.html")
require.NoError(t, err)
require.NoError(t, res.Body.Close())
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice tests 👍

@jawnsy jawnsy merged commit f7b4849 into main Feb 19, 2022
@jawnsy jawnsy deleted the jawnsy/chore-add-caching branch February 19, 2022 03:34
@jawnsy jawnsy removed their assignment Mar 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants