【发布时间】:2020-01-07 00:55:03
【问题描述】:
我有主站点(site.com)和我的资源(css、图像、js)所在的站点(somecdn.com)。我想在登录之前推送一些这样的资源。我发送 ajax 请求并在响应头中设置 Link-s 与资源。但是我的资源在等待并且没有任何推送的情况下下载(见附图)。如何在 somecdn.com 中启用 http2 推送资源? with push without push
我在 docker 中创建了两个站点:site.com 和 somecdn.com,并检查 http2 push 在它们上是否正常工作(并且分别按预期工作)。
https://127.0.0.1:8081/index.php
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>IndexPHP</h1></iframe>-->
<script>
window.onload = function () {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://127.0.0.1:8083/push.php', true);
xhr.send();
}
</script>
</body>
</html>
https://127.0.0.1:8083/push.php
<?php
header("Link: </style.css>; rel=preload; as=style", false);
header("Link: </image.png>; rel=preload; as=image", false);
我希望无需等待并带有“推送”指示即可在 Chrome 开发工具资源中查看。
【问题讨论】: