如何使 Symfony 2 资产编译产生不同的文件名? [英] How to make Symfony 2 asset compilation to product different filenames?

查看:17
本文介绍了如何使 Symfony 2 资产编译产生不同的文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了本文最底部的指南:http://symfony.com/doc/current/cookbook/assetic/asset_management.html

I followed the guide on the very bottom of this article: http://symfony.com/doc/current/cookbook/assetic/asset_management.html

我有这个代码:

    {% javascripts
        ...

        output='js/dist/dist.js'
    %}
    <script src="{{ asset_url }}"></script>
    {% endjavascripts %}

现在,如果我运行 sf assetic:dump --env=prod 它会正确创建编译文件.但是,我希望它生成一个随机名称(或时间戳),以避免客户端浏览器缓存问题.现在它总是创建被缓存的 dist.js 文件,当我更新我的代码时,用户不会看到差异(或出现错误).

Now if I run sf assetic:dump --env=prod it creates the compiled file properly. However, I would like to have it generating a random name (or timestamped) so that the client-side browser cache problem is avoided. Right now it always creates dist.js file which gets cached and when I update my code the users won't see the difference (or get errors).

有没有办法让它像dist12345678.js?

推荐答案

您在这里有两个选择:要么省略输出文件名(然后它将是一个自动生成的更改哈希)或使用资产版本,如Symfony 文档:http://symfony.com/doc/current/reference/configuration/framework.html#ref-framework-assets-version

You have two options here: Either leave out the output file name (it will then be an autogenerated hash that changes) or use asset versions, as described in the Symfony docs: http://symfony.com/doc/current/reference/configuration/framework.html#ref-framework-assets-version

这篇关于如何使 Symfony 2 资产编译产生不同的文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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