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(nginx): enable gzip compression and cache control for static files #660

Merged

Conversation

paularmstrong
Copy link
Contributor

Before (without images, transfer size = 116kB)
1-after

After (without images, transfer size = 52kB)
Screen Shot 2021-01-29 at 8 22 34 AM

Closes #653

location ~* \.(?:js|css|svg|ico|png)$ {
access_log off;
expires 1y;
add_header Cache-Control "public";
Copy link
Owner

Choose a reason for hiding this comment

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

Should we set a corresponding Cache-Control header for the api and html endpoints to ensure they don't get cached?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense to me. Updated the /api and default for web.

 ★  curl -I http:https://localhost:5000/api/events
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Fri, 29 Jan 2021 17:43:37 GMT
Content-Type: application/json
Content-Length: 1188808
Connection: keep-alive
Vary: Accept-Encoding
Access-Control-Allow-Origin: *
Cache-Control: no-store

 ★  curl -I http:https://localhost:5000/
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Fri, 29 Jan 2021 17:43:46 GMT
Content-Type: text/html
Connection: keep-alive
Vary: Accept-Encoding
Cache-Control: no-cache

 ★  curl -I http:https://localhost:5000/favicon.ico
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Fri, 29 Jan 2021 17:43:52 GMT
Content-Type: image/x-icon
Content-Length: 15086
Last-Modified: Fri, 29 Jan 2021 16:20:14 GMT
Connection: keep-alive
ETag: "601435be-3aee"
Expires: Sat, 29 Jan 2022 17:43:52 GMT
Cache-Control: max-age=31536000
Cache-Control: public
Accept-Ranges: bytes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking again, I'd like to make sure JSON api responses get gzipped correctly. Going to update again…

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, that's better. Required the gzip_proxied line.

@paularmstrong paularmstrong changed the base branch from master to release-0.8.1 January 30, 2021 17:17
@paularmstrong paularmstrong merged commit eb92f6d into blakeblackshear:release-0.8.1 Jan 30, 2021
@paularmstrong paularmstrong deleted the nginx_gzip_cache branch January 30, 2021 18:23
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.

nginx: ensure compression and caching are enabled for all appropriate responses
2 participants