flipzoom / ProcessWire-AIOM-All-In-One-Minify

AIOM+ (All In One Minify) is a ProcessWire module to easily improve the performance of your website. By a simple function call Stylesheets, LESS and Javascript files can be parsed, minimized and combined into one single file. This reduces the server requests, loading time and minimizes the traffic. In addition, the generated HTML source code can be minimized and all generated files can be loaded over a cookieless domain (domain sharding).
MIT License
33 stars 26 forks source link

Cache filename collision #64

Open mackski opened 7 years ago

mackski commented 7 years ago

If an array of filenames are passed, and all files have the same modified timestamp on separate pages a collision will occur and the wrong file is served for subsequent pages.

eg: Page 1 - array('file1.js','file2.js'); Page 2 - array('file1.js','file3.js');

Each file has the same timestamp (ie; rsync or similar copy operation).

Simple fix: $_timestamp = ($_timestamp + $file['last_modified'] . basename($file['absolute_path']));

janKir commented 7 years ago

Got the same problem. I haven't tried your solution but isn't there a problem with adding a string to the timestamp because it is used for the arithmetic + operation in the next iteration? I did basically the same but using the decimal hash of the filename: $_timestamp = ($_timestamp + $file['last_modified'] + hexdec(md5(basename($file['absolute_path']))));

thuijzer commented 6 years ago

We also had this problem. My fix:

private static function _getCacheName($files, $prefix = 'css_', $ext = '.css') {
    $hash = md5(print_r($files, true));

    return (self::$developmentMode !== true) ? $prefix.$hash.$ext : $prefix.$hash.'_dev'.$ext;
}