问题
I'm using assetic with symfony and I'd like to append a timestamp or date string to the end of the filenames it creates.
The purpose of this is to have more control over browser caching, so every time I run assetic:dump, all my compiled assets will have a new file name and users browsers will download the new file.
Is this the best way to prevent browsers using old (cached) asset files?
If it is, how do I append the timestamp to the filenames?
回答1:
I suggest, in order to have control over browser's cache, do the following:
app/config/config.yml
framework:
templating:
assets_version: %assets_version%
This setting will make assetic append ?vX
to asset url (X
is your %asset_version%
parameter).
parameters.yml
parameters:
assets_version: 1
You need to change your asset version each time you want to deploy new version of assets and make user browser to fetch new content.
There is also AssetsVersionBundle which adds command to increase %assets_version%
for you. Just type
app/console assets_version:increase
Documentation of this bundle covers assets versioning issue pretty well
来源:https://stackoverflow.com/questions/28034456/in-symfony2-how-can-i-append-a-date-to-the-assetic-filenames