douzhuan4406 2011-10-09 10:37
浏览 71
已采纳

检查每个请求的javascript / css文件修改时间

We have two files in header of every web page - a ccs and a javascript file:

<script type="text/javascript" src="/js/scripts.js?1234"></script>
<link href="styles.css?2345" rel="stylesheet" type="text/css" />

Every time we modify a css/javascript file we increase the ?1234 parameter in the end of filename. Recently a member of the team proposed to replace this manual updating (that we have sometimes forgot to do) with PHP code that checks the file modification time itself:

<script type="text/javascript" src="/js/scripts.js?<?php echo filemtime('/js/scripts.js');?>"/>
<link href="styles.css?<?php echo filemtime('styles.css');?>" rel="stylesheet" type="text/css" />

The question is that how much slower (if at all) it makes the requests? Should we do it? We run our system in Linux server on Amazon EC2.

  • 写回答

2条回答 默认 最新

  • dsfgds4215 2011-10-09 10:42
    关注

    Filetime is slow but using it 2 times in a webpage maybe ok. But I would cache the result and only update it sometime (with a conjob for example).

    Well if you are checking 1000 files, filemtime will actually DOUBLE the amount of time used if just reading the file with file_get_contents!

    -> http://ckon.wordpress.com/2008/09/16/filemtime-the-performance-killer/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因