
[[Md5File? &file=`full/path/to/file`]]
<?php /* MD5File snippet */ return md5_file($scriptProperties['file']);
<script src="assets/js/my-module.js"></script>
<script src="assets/js/my-module.js?build=1447511cd64b5b437824eae28319cab8"></script>

<script src="assets/js/my-module.js?build=[[Md5File? &file=`assets/js/my-module.j`]]"></script>
<script src="[[Md5File? &file=`assets/js/my.js`]]"></script>
<?php /* MD5File snippet */ return '/' . $scriptProperties['file'] . '?build=' . md5_file($scriptProperties['file']);
<script src="[[!Md5File? &file=`assets/js/my.js`]]"></script>
<?php
/* MD5File snippet */
$path = $scriptProperties['file'];
$result = split('=',exec("openssl md5 $path"));
return '/' . $path . '?build=' . $result[1]);
$modx->regClientCSS($path . '?build=' . $version);
That's a very cool idea, though I think you'd need to call it uncached for it to work:
<script src="[[!Md5File? &file=`assets/js/my.js`]]"></script>
Also, you're going to do a full hash of the entire file every time the page loads and md5_file() is not noted for its speed. This would be about 3x faster if it works on your server:
<!--?php /* MD5File snippet */ $path = $scriptProperties['file']; $result = split('=',exec("openssl md5 $path")); return '/' . $path . '?build=' . $result[1]);
Much faster yet (for the user) would be to just append a version number manually, though if you've got a lot of files I can see why you might not want to do it that way.
Here's what I generally do:
$modx--->regClientCSS($path . '?build=' . $version);
If you got the time, please show me an example of how to use it the full way.
[[AddCss? &path=`path/to/file` &version=`1.1`]]
/* Add Css snippet */
$modx->regClientCSS($scriptProperties['path'] .
'?build=' . $scriptProperties['version']);
return '';Yes, clearing the site cache would take care of the problem and you could call it cached, which should make it much faster (though not as fast as the exec version).
As for my snippet, I'm not sure how much faster it would be, but the file's hash value would never have to be calculate. Hash methods like md5 are intentionally slow to make it harder to do a brute-force attack. My snippet would work like this:
[[AddCss? &path=`path/to/file` &version=`1.1`]]
/* Add Css snippet */ $modx->regClientCSS($scriptProperties['path'] . '?build=' . $scriptProperties['version']); return '';

