Opened 7 years ago

Last modified 4 years ago

#1188 new enhancement

Send "immutable" keyword in Cache-Control when "expires max"

Reported by: fazalmajid@… Owned by:
Priority: minor Milestone:
Component: nginx-module Version: 1.11.x
Keywords: Cc:
uname -a: SunOS mordac 5.11 joyent_20160218T022556Z i86pc i386 i86pc
nginx -V: nginx version: nginx/1.11.8
built by gcc 6.3.0 (GCC)
built with OpenSSL 1.1.0c 10 Nov 2016
TLS SNI support enabled
configure arguments: --prefix=/usr/local --conf-path=/usr/local/etc/nginx --with-ipv6 --with-http_ssl_module --with-http_realip_module --with-select_module --with-poll_module --with-http_stub_status_module --with-http_gzip_static_module --without-http_scgi_module --without-http_uwsgi_module --with-cc-opt='-I/usr/local/include -I/usr/local/ssl/include -DNGINX_DTRACE=1' --with-ld-opt='-L /usr/local/lib -L /usr/local/ssl/lib' --error-log-path=/tmp/nginx_error.log --with-http_v2_module --with-http_auth_request_module --with-stream


Per the documentation for ngx_http_headers_module:

The max parameter sets “Expires” to the value “Thu, 31 Dec 2037 23:55:55 GMT”,
and “Cache-Control” to 10 years.

At Facebook's urging, Firefox implemented an additional keyword to Cache-Control for immutable assets:

Adding this "immutable" keyword to the Cache-Control header for "expires max" requests would improve cache effectiveness for Firefox users.

The change itself is trivial:

--- src/http/modules/ngx_http_headers_filter_module.c.dist      Thu Jan 26 11:14:29 2017
+++ src/http/modules/ngx_http_headers_filter_module.c   Thu Jan 26 11:15:23 2017
@@ -301,7 +301,7 @@
     if (expires == NGX_HTTP_EXPIRES_MAX) {
         e-> = (u_char *) "Thu, 31 Dec 2037 23:55:55 GMT";
         /* 10 years */
-        ngx_str_set(&cc->value, "max-age=315360000");
+        ngx_str_set(&cc->value, "max-age=315360000, immutable");
         return NGX_OK;

Change History (5)

comment:1 by Ruslan Ermilov, 7 years ago

What's wrong with add_header Cache-Control immutable;?

in reply to:  1 comment:2 by carrete@…, 7 years ago

Replying to ru:

What's wrong with add_header Cache-Control immutable;?

Primarily because of:

Inheritance Rules for add_header Directives

NGINX configuration blocks inherit add_header directives from their enclosing blocks, so you just need to place the add_header directive in the top-level server block. There’s one important exception: if a block includes an add_header directive itself, it does not inherit headers from enclosing blocks, and you need to redeclare all add_header directives:


I replaced "expires max" with two add_header directives for Expires and Cache-Control which disabled add_header directives that were set elsewhere, notably for Strict-Transport-Security and X-Frame-Options.

comment:3 by eoghanmurray@…, 5 years ago

Cache-Control: ...,immutable; support is also in Webkit:

Edge appears to have it since v15:

(Chromium is wontfix: )

I think this would be great to add with expires max and I (naïvely) can't see any downside :D

comment:4 by dvershinin@…, 4 years ago

I've created ngx_immutable module so one can specify immutable on; in lieu of expires max;.

comment:5 by Maxim Dounin, 4 years ago

See also #2100.

Note: See TracTickets for help on using tickets.