In Symfony2 how can I append a date to the assetic filenames

妖精的绣舞 提交于 2019-12-22 12:36:24

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!