Skip to content

Commit a7726fc

Browse files
committed
use http2_push instead of http2_push_preload
This avoids needing to conditionally add nopush to each preloaded resource in the Link header. There's also no support for pushing JavaScript modules via http2_push_preload since nginx doesn't have support for rel=modulepreload.
1 parent f03fafc commit a7726fc

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

nginx/nginx.conf

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,22 @@ http {
9191
default 0;
9292
}
9393

94-
map $nopush $preload_resources {
95-
1 "<{{path|/main.css}}>; rel=preload; nopush; as=style; integrity={{integrity|/main.css}}, </fonts/roboto-v29-regular-latin.woff2>; rel=preload; nopush; as=font; crossorigin, </fonts/roboto-v29-bold-latin.woff2>; rel=preload; nopush; as=font; crossorigin";
96-
default "<{{path|/main.css}}>; rel=preload; as=style; integrity={{integrity|/main.css}}, </fonts/roboto-v29-regular-latin.woff2>; rel=preload; as=font; crossorigin, </fonts/roboto-v29-bold-latin.woff2>; rel=preload; as=font; crossorigin";
97-
}
98-
9994
map $nopush $push_cookie {
10095
0 "__Host-preload=1; HttpOnly; Secure; SameSite=Lax; Path=/";
10196
}
10297

98+
map $nopush $push_stylesheet {
99+
0 "{{path|/main.css}}";
100+
}
101+
102+
map $nopush $push_font_regular {
103+
0 /fonts/roboto-v29-regular-latin.woff2;
104+
}
105+
106+
map $nopush $push_font_bold {
107+
0 /fonts/roboto-v29-bold-latin.woff2;
108+
}
109+
103110
server {
104111
listen 80 backlog=4096;
105112
listen [::]:80 backlog=4096;

nginx/snippets/preload.conf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
add_header Link $preload_resources always;
1+
add_header Link "<{{path|/main.css}}>; rel=preload; as=style; integrity={{integrity|/main.css}}, </fonts/roboto-v29-regular-latin.woff2>; rel=preload; as=font; crossorigin, </fonts/roboto-v29-bold-latin.woff2>; rel=preload; as=font; crossorigin" always;
22
add_header Set-Cookie $push_cookie always;
3-
http2_push_preload on;
3+
http2_push $push_stylesheet;
4+
http2_push $push_font_regular;
5+
http2_push $push_font_bold;

process-static

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ for file in static-tmp/**/*.css static-tmp/**/*.js; do
3939
replace+=";s@{{path|/${file#*/}}}@/${dest#*/}@g"
4040
done
4141

42-
sed -i "$replace" static-tmp/**/*.html nginx-tmp/nginx.conf
42+
sed -i "$replace" static-tmp/**/*.html nginx-tmp/nginx.conf nginx-tmp/snippets/preload.conf
4343

4444
gixy nginx-tmp/nginx.conf
4545

0 commit comments

Comments
 (0)