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

Add Cache-Control header to static resources to help caching #901

Merged
merged 1 commit into from
Jan 24, 2020
Merged

Conversation

nzmsv
Copy link
Contributor

@nzmsv nzmsv commented Jan 15, 2020

Changes

Prior to this change putting the dashboard behind ALB broke static resource caching. ALB seems to remove the Date header from the response it proxies, however it will obey explicit Cache-Control headers.

Static resources coming from webpack already have a content hash as part of their name so they are already immutable.

Note: the first draft of this PR used the Etag header instead. See the discussion below.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@tekton-robot tekton-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 15, 2020
@tekton-robot
Copy link
Contributor

Hi @nzmsv. Thanks for your PR.

I'm waiting for a tektoncd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@a-roberts
Copy link
Member

/ok-to-test
@AlanGreene FYI

@tekton-robot tekton-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 16, 2020
@a-roberts
Copy link
Member

/test tekton-dashboard-unit-tests

Copy link
Member

@AlanGreene AlanGreene left a comment

Choose a reason for hiding this comment

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

@nzmsv thanks for the PR, adding caching support would be very useful for a lot of use cases.

Since the URLs for the static resources already contain a content-based hash we know that content can be cached long-term without requiring periodic revalidation as in the case of using entity tags or similar approaches. Instead of sending the Etag header in the response, we could set a long max-age on the Cache-Control header and eliminate the conditional requests from the browser.

Something like Cache-Control: public, max-age=31536000, immutable

Would this work for your use case?

@nzmsv
Copy link
Contributor Author

nzmsv commented Jan 22, 2020

@nzmsv thanks for the PR, adding caching support would be very useful for a lot of use cases.

Since the URLs for the static resources already contain a content-based hash we know that content can be cached long-term without requiring periodic revalidation as in the case of using entity tags or similar approaches. Instead of sending the Etag header in the response, we could set a long max-age on the Cache-Control header and eliminate the conditional requests from the browser.

Something like Cache-Control: public, max-age=31536000, immutable

Would this work for your use case?

Thanks, this is a great idea! I tested the Cache-Control header behind ALB and it works correctly. I updated the PR accordingly.

@nzmsv nzmsv changed the title Add etags to static resources to help caching Add Cache-Control header to static resources to help caching Jan 22, 2020
pkg/router/router.go Outdated Show resolved Hide resolved
Prior to this change putting the dashboard behind ALB
broke static resource caching.  ALB seems to remove the
Date header from the response it proxies, however it obeys
explicit Cache-Control headers.

Static resources coming from webpack already have a content hash
as part of their name so we can already assume each URL points to
an immutable resource.
@AlanGreene
Copy link
Member

/test tekton-dashboard-unit-tests

Copy link
Member

@AlanGreene AlanGreene left a comment

Choose a reason for hiding this comment

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

/lgtm
/meow hats

@tekton-robot
Copy link
Contributor

@AlanGreene: cat image

In response to this:

/lgtm
/meow hats

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 24, 2020
@tekton-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AlanGreene

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 24, 2020
@AlanGreene
Copy link
Member

/test tekton-dashboard-unit-tests

@tekton-robot tekton-robot merged commit f829230 into tektoncd:master Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants