I would like to avoid browser cache on my images by appending the SVN revision number after each images like this (in the same fashion than this answser):
<?php $v = getRevisionNumber() ?>
<img src="picture.jpg?v=<?= $v ?>" alt="">
Is there a way to do it automatically in Symfony 1.4 (like this for js/css, but with images instead)
Also, how can I do it for an image that is in a css file ?
#title {
background-image: url(/images/title.png);
}
I found something interesting in the symfony tracker, for the version 1.3/1.4, there were a patch to automatically add a timestamp to all files in the web directory: http://trac.symfony-project.org/ticket/6135
It has been reverted since, no idea why … (to intrusive?).
Override the default asset helper
Anyway, I think you have to create your own AssetHelper (copied all contents from the current one) and add & customize the patch #6135 into a
lib/helper/CustomAssetHelper.php.But you can’t unload the AssetHelper because it is automatically loaded in the core: http://trac.symfony-project.org/browser/branches/1.4/lib/view/sfPHPView.class.php#L33 So there will be conflict since you will have duplicate function (in AssetHelper and CustomAssetHelper).
Add a custom template engine
The idea is to have a custom
sfPHPViewto redefine theloadCoreAndStandardHelpersto call your own asset helper (put it inlib/view/sfCustomPHPView.class.php):To change the default sfPHPView, you need to add a
module.ymlinconfig/orapps/frontend/config/with the following contents (inspired from sfTwigPlugin):Override all
image_tag()As Yzmir Ramirez said,
image_tag()callsimage_path()which call_compute_public_path($source, 'images', 'png', $absolute);.In
_compute_public_pathfunction, before the last condition, you customize the query_string to add your own revision number (which will be define somewhere else – sfConfig for example):It might be a bit complex but using this way, you can override image_tag function and add the version number you want without redefine all you image_tag() call.
About image inside a CSS, it’s a bit more complex since you will have to parse css or write css in PHP. No idea about the best way to do.