dongpinyao2203 2013-06-14 18:08
浏览 51

使用PHP将HTML刷新到浏览器

I am trying to implement the trick listed on this page http://developer.yahoo.com/performance/rules.html#flush "Flush the Buffer Early".

Everytime I try to run this thing I am not getting the desired output.

I have written the following code.

<html>
<head>
    <title>This is title</title>
    <script type="text/javascript" src="/1.js"></script>
    <link rel="stylesheet" type="text/css" href="/1.css">
</head>

<body>
ABC
<?php
flush();
sleep(3);
?>
</body>
</html>

The result enter image description here

I am getting the same result on both Firefox and Chrome.

What I expect is that the download of CSS and JS files should start immediately, and not wait for 3 seconds.

Based on the information given on the internet, I have tried the following things but nothing has helped.

1. ob_start(); and then ob_flush();

2. Using both ob_flush(); and flush(); ( in both the orders )

3. Adding the thing like this
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);

4. Putting more content in body 4~5 KB of content before flush.

5. And many other things.

I doubt if achieving this kind of thing is actually possible.

  • 写回答

2条回答 默认 最新

  • douya2982 2013-06-14 18:19
    关注

    Hum... In yahoo's document, flush() was after </head> and before <body>.

      ... <!-- css, js -->
    </head>
    <?php flush(); ?>
    <body>
      ... <!-- content -->
    

    In your code, It's inside <body>. Did you tried to put the php code before it?

    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler