duanmu5641 2014-06-17 08:01
浏览 71
已采纳

PHP检查浏览器缓存中是否存在url

My web project is based on XSLT created XHTML pages which takes some time to be created. On the other side, the original XML changes rarely. Therefore, I set a browser cache with a HTTP header in PHP:

header("Cache-Control: public, max-age=3600"); 

Going "back" and "forward" in the browser is now very smooth.

But there is another case: By clicking on some links the user could possibly get the very same page again. The URL is also exactly the same. But in this case the page isn't loaded from the browser cache, but created anew. I've found a very nice solution for a server cache on http://www.webgeekly.com/tutorials/php/learn-how-to-cache-content-with-php-in-under-5-minutes/ . But retrieving the file from the browser cache would even be faster.

So, is there a way in PHP to do this:

  • check whether a certain URL part (like "output.php?id_of_search=123454&action=select") is in the browser cache
  • if yes: Load the page with that URL from the browser cache.

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • duanmei1694 2014-06-17 08:27
    关注

    If your php-script is executed the browser already decided not to use its cache. Otherwise it would not request your page at all and just serve the user from cache. Meaning: There is no way to trigger the cache at that time from php.

    The reason why it is not using the cache, is because the browser thinks the result will be another page. So if you make sure the same page has always the same URL linking to it, the cache will work fine.

    One pitfall here might be

    http://example.com/somepage.php
    http://example.com/somepage.php?someparam=1
    http://example.com/somepage.php?someparam=2
    

    These URL all generate the same response, but the browser thinks they are different.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。