This repository was archived by the owner on Apr 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 156
This repository was archived by the owner on Apr 10, 2025. It is now read-only.
Attempting to extend cache for SVGs returns bad headers/content. #1496
Copy link
Copy link
Closed
Description
In relation to #1221, I decided to try and extend the cache on SVGs and fonts that I had hashed outside of Pagespeed. With pagespeed off, everything works great, with the following headers returned.
HTTP/1.1 200 OK
Connection: keep-alive
Server: nginx
Date: Mon, 20 Feb 2017 05:34:29 GMT
Content-Type: image/svg+xml
Last-Modified: Mon, 20 Feb 2017 03:05:29 GMT
Transfer-Encoding: chunked
Etag: W/"58aa5cf9-b24"
Expires: Tue, 20 Feb 2018 05:34:29 GMT
Cache-Control: max-age=31536000
Content-Encoding: gzip
Via: 1.1 vegur
(Except that Etag looks odd)
However, with pagespeed on, I get the following, plus Chrome gives net::ERR_CONTENT_DECODING_FAILED.
HTTP/1.1 200 OK
Connection: keep-alive
Content-Type: image/svg+xml
Server: nginx
Last-Modified: Mon, 20 Feb 2017 06:25:12 GMT
Etag: "58aa8bc8-b24"
Accept-Ranges: bytes
Date: Mon, 20 Feb 2017 06:31:33 GMT
Expires: Tue, 20 Feb 2018 06:31:33 GMT
Vary: Accept-Encoding
X-Original-Content-Length: 2852
Content-Encoding: gzip
Content-Length: 1032
Etag: "58aa8bc8-b24"
Cache-Control: max-age=31536000, s-maxage=10
Accept-Ranges: bytes
Via: 1.1 vegur
Note that Etag and Accept-Ranges are both repeated.
The error appears to be because the content is no longer gzipped, though the header says otherwise. I tried to achieve this with the following config.
Config extract
http {
gzip on;
gzip_comp_level 2;
gzip_min_length 512;
gzip_proxied any;
gzip_types
text/css
text/javascript
text/xml
text/plain
application/javascript
application/x-javascript
application/json
image/svg+xml;
gzip_http_version 1.0;
server_tokens off;
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
...
set $staticdir /app/staticfiles/;
location /static {
autoindex on;
alias $staticdir;
}
# Adding hashes for these assets, but pagespeed doesn't set cache headers
location ~* "/static/(.*\.[0-9a-f]{12}\.(?:svg|svgz|woff))$" {
expires 1y;
access_log off;
alias $staticdir/$1;
}
pagespeed on;
pagespeed EnableFilters prioritize_critical_css;
pagespeed UrlValuedAttribute div img-src image;
# Needs to exist and be writable by nginx. Use tmpfs for best performance.
pagespeed FileCachePath /app/var/ngx_pagespeed_cache;
# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
}
}
Interestingly, the woff fonts are fine. Turning off Gzipping for image/svg+xml returns the same broken headers.
Hopefully I have just made a silly config error. Any help much appreciated.
Metadata
Metadata
Assignees
Labels
No labels