我一直在寻找一种方法来减少我网站上的HTTP标头权重。例如,当前,我的网站上有以下资源:
https://example.com/
https://example.com/style.css
https://example.com/custom.js
https://example.com/font.woff2
https://example.com/anotherfont.woff2
https://example.com/logo.png
说,我想通过在我的vhost中包含如下代码段来使用HTTP标头推送/预加载资源:
http2_push_preload on;
more_set_headers "Link </logo.png>; rel=preload; as=image,</font.woff2>; rel=preload; as=font; crossorigin,</style.css>; rel=preload; as=syle";
这样做可以执行“推送/预加载”,但问题是在每个资源的HTTP响应上都显示了“预加载标头”。
我希望预加载HTTP标头仅可用于主索引URL,例如:
https://example.com/
https://example.com/article/
以上URL应该具有Preload HTTP标头,但是静态资源的HTTP响应不应具有Preload标头,因为它对我没有意义。
到目前为止,我已经尝试了以下代码段,但它不起作用:
location ~* \.(html|text/html)$ {
http2_push_preload on;
more_set_headers "Link </logo.png>; rel=preload; as=image,</style.css>; rel=preload; as=syle";
}