【问题标题】:Implementing http2 push method on apache php在 apache php 上实现 http2 推送方法
【发布时间】:2019-11-21 06:24:17
【问题描述】:

我已经在 http2 上配置了我的网站,但即使阅读了这么多文章,我也无法弄清楚它的一些实现。

我已经从我网站的头文件中删除了common.css。并将这些行添加到.htaccess 文件中。

<IfModule http2_module>
    #Check if there's a cookie saying the css has already been loaded: 
    SetEnvIf Cookie "cssloaded=1" cssloaded
    #If no cookie, and it's an html file, then push the css file 
    #and set a session level cookie so next time it won't be pushed: 
    <filesMatch "\.([pP][hH][pP]?)">
            Header add Link "</assets/css/common.css>;rel=preload;as=style" env=!cssloaded
            Header add Set-Cookie "cssloaded=1; Path=/; Secure; HttpOnly" env=!cssloaded
    </filesMatch>
</IfModule>

但是我的网站根本没有加载common.css。它坏了。我的网站位于 Apache 服务器之后,并且网站完全建立在 codeIgniter 之上。

我也确实将这些添加到了我的 common_head.php 文件中

<?php
        header: header('Link: </assets/css/jquery-ui.css>; rel=preload; as=style,</assets/css/jquery.mCustomScrollbar.min.css>; rel=preload; as=style,</assets/css/slick.min.css>; rel=preload; as=style,</assets/css/slick-theme.min.css>; rel=preload; as=style,</assets/css/bootstrap.min.css>; rel=preload; as=style,</assets/css/common.css>; rel=preload; as=style,,</assets/css/jplayer.blue.monday.min.css>; rel=preload; as=style');
?>

现在我可以在检查元素中看到所有的 css 文件,也可以看到初始化程序推送/其他,但它不适用于页面。页面已损坏。 阿帕奇服务器:2.4.6

请告诉我哪里做错了?

【问题讨论】:

    标签: php apache .htaccess http2


    【解决方案1】:

    这段代码看起来很眼熟!很高兴知道my blog post 被证明是有用的:-)

    我已经从我的网站的头文件中删除了 common.css。并将这些行添加到 .htaccess 文件中。

    那是你出错的地方。它需要在 HEAD 中正常引用并推送。

    当浏览器看到 common.css 引用时,它会去获取它并看到它已经被推送并使用推送的资源。

    如果没有引用,服务器会推送它,但浏览器会忽略它。

    注意 HTTP/2 推送很复杂,有很多这样的事情可能会出错。有关更多信息,请参阅此帖子:https://jakearchibald.com/2017/h2-push-tougher-than-i-thought/。许多人说使用它不值得获得收益,而且无论如何收益都是值得怀疑的,因为您很容易过度推动并导致页面加载速度变慢而不是更快。

    【讨论】:

      猜你喜欢
      • 2018-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-25
      • 2018-10-21
      • 2018-09-06
      • 2018-07-24
      • 2018-10-30
      相关资源
      最近更新 更多