在 Symfony2 中,如何将日期附加到资产文件名 [英] In Symfony2 how can I append a date to the assetic filenames

查看:33
本文介绍了在 Symfony2 中,如何将日期附加到资产文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 symfony 的资产,我想在它创建的文件名的末尾附加一个时间戳或日期字符串.

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.

这样做的目的是为了更好地控制浏览器缓存,所以每次我运行 assetic:dump 时,我所有编译的资产都会有一个新的文件名,用户浏览器将下载新文件.

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?

推荐答案

我建议,为了控制浏览器的缓存,请执行以下操作:

I suggest, in order to have control over browser's cache, do the following:

app/config/config.yml

framework:
   templating:
       assets_version: %assets_version%

此设置将使资产附加 ?vX 到资产网址(X 是您的 %asset_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.

还有 AssetsVersionBundle 增加了增加 %assets_version% 的命令你.只需输入

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

这篇关于在 Symfony2 中,如何将日期附加到资产文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆