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: set cache headers for static assets #999

Merged
merged 2 commits into from
Apr 26, 2021
Merged

Conversation

AntoineAugusti
Copy link
Contributor

@AntoineAugusti AntoineAugusti commented Apr 26, 2021

Fixes cds-snc/notification-api#1152

This PR adds appropriate Cache-Control headers for static assets (JS, CSS, images) served by the admin. This will improve the user experience for users, reduce the number of requests we have to handle and our costs.

Cache invalidation is done thanks to an asset fingerprinter. I've made sure that templates don't use hardcoded paths anymore by looking for thinks like static/, asset_path and admin_base_url in the codebase.

@maxneuvians maxneuvians temporarily deployed to notification-cache-stat-zbtgya April 26, 2021 12:41 Inactive
@AntoineAugusti AntoineAugusti marked this pull request as ready for review April 26, 2021 12:43
# as they have unique hashes thanks to the asset
# fingerprinter
if request.url.startswith(asset_fingerprinter._asset_root):
response.headers.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.

just so you are aware: immutable is only support on Firefox, Safari

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AntoineAugusti AntoineAugusti enabled auto-merge (squash) April 26, 2021 13:02
app/__init__.py Outdated Show resolved Hide resolved
@maxneuvians maxneuvians temporarily deployed to notification-cache-stat-zbtgya April 26, 2021 13:17 Inactive
Copy link
Contributor

@QuanNguyen-CDS QuanNguyen-CDS left a comment

Choose a reason for hiding this comment

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

thank you, looks good

@AntoineAugusti AntoineAugusti merged commit d7d7b59 into master Apr 26, 2021
@AntoineAugusti AntoineAugusti deleted the cache-static-assets branch April 26, 2021 13:41
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.

Static assets caching
3 participants