Symfony generate cdn friendly asset url

。_饼干妹妹 提交于 2019-12-24 19:07:16

问题


I have a symfony application that gets served by a cdn (eg. akamai) and I generate the asset url on the templates with:

{{ asset('myJs.js') }}

When I do I want to generate a url like (supposing that the site is served by www.example.com) :

www.example.com/myJs.js?v=321321312312

Where the v parameter get a deployed version in order to force cdn (eg. akamai network) to cache me newer version. Is it a good way to dynamically generate the v parameter?


回答1:


If you want to append a hash to the file that is kept unique per version, you could either use the file modification time of that file or a hash. The best way could be to create a new Twig function versionedAsset() that uses the output of asset() and appends this hash to the generated URL




回答2:


src="www.example.com/myJs.js?v={{ random() }}"



来源:https://stackoverflow.com/questions/47633497/symfony-generate-cdn-friendly-asset-url

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