drm30963 2017-02-23 06:34
浏览 86

包括Http2的头,包括用于服务器推送的php中的css,js和文件

After successfully including the http2 in apache2. I was facing the problem for the server push. I have 4-5 css ,4-5 js and 100 images in the site. So how would i work with multiple assets?

    <link href="source" rel="stylesheet">
    <script src="source"></script>
    <img src="source">
   header('Link: </asset/to/push.js>; rel=preload; as=script')

so i have to header for each and every assets if i have 100 assets there will be 100 header or so

  • 写回答

2条回答 默认 最新

  • doufusi2013 2017-02-23 08:31
    关注

    An alternative solution to adding the Link headers and have Apache parse them and push the associated resources, is to naturally correlate secondary resources such as js, css and image files to the primary resource.

    This is the approach that we have taken in Jetty (disclaimer, I am the implementor of that solution).

    We use this solution to serve our own Website, based on WordPress, over HTTP/2 with HTTP/2 Push.

    The approach is presented here: slides, video.

    The basic idea is that when a browser received an HTML page, it immediately parses it and perform the requests needed to download secondary resources such as js and css files. The server, in this case Jetty, can correlate the primary resource (the html) with the secondary resources.

    The next time a request for the same html page arrives, Jetty already knows what are the secondary resources needed, and can push them. There is no need for Link headers, as Jetty "learns" what are the resources needed by a page from the request patterns that the browser performs.

    This approach can be fine tuned on basis to basis, but works fine out of the box and provides dramatic performance improvements, see here for the live demo in the video linked above.

    I recommend to read/watch the whole slides/video for a larger context about HTTP/2 and HTTP/2 Push, but the point is that the combination Jetty + PHP with HTTP/2 is a powerful solution for HTTP/2 Push and requires no changes to PHP pages - which is perfect when using PHP frameworks such as WordPress or Drupal, and to avoid adding 100+ Link headers to your PHP pages.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line