0
votes

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?

2
“Where the v parameter get a deployed version in order to force cdn (eg. akamai network) to cache me newer version.” - what do you think this has to do with caching on the CDN side ...? This technique is commonly used to handle caching on the client side ("cache buster", to prevent the client from serving outdated resources from cache.) - CBroe

2 Answers

1
votes

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
votes

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