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条)

报告相同问题?

悬赏问题

  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复