检查每个请求的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.

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/

Execute this on your server:

$start = microtime(true);
for ($i = 0; $i < 5000; ++$i) {
    filemtime('styles.css');
    filemtime('/js/scripts.js'); //Seriously, is this file on the root of you server? I don't think so :)
}
echo 'Seconds slower: ' . ((microtime(true) - $start) / 5000) . '.';

And it will give you the seconds :)

But, how often do you change an CSS & JS file? If it's every minute, than it's really helpful, but if it's every month, it's useless I think.