问题
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