Symfony2 Assetic Create URLs pointing to CDN

Is there a way to extend Assetic so that it can load my images from a CDN that I am setting up somewhere else. If I can write a plugin / extension / event listener / etc that allows you to control small grains, that would be awesome.

Also, are there any hooks for the assetic: dump console command that I could use when I dump, I can automatically push the images from the local field to the CDN (since I want the images to be loaded locally on dev)

Basically, I want to have images sitting somewhere on my local machine, say: Web / images / image.png

On dev, when I do something like:

asset('images/image.png') 

It would splash out such a url on dev:

 http://1.2.3.4/images/image.png 

And in the production, he spat out something like:

 http://my.cdn.net/images/image.png 

And when I run assetic: dump, the image automatically loads.

Thanks.

+4
source share
2 answers

Check out this link: http://symfony.com/doc/master/reference/configuration/framework.html#assets-base-urls

You can add a base url to your config.yml, for example:

 framework: templating: assets_base_urls: http: my.cdn.net 
+5
source

Starting with Symfony 2.7, the configuration has changed:

 framework: assets: base_urls: - 'http://cdn.example.com/' 

check out: http://symfony.com/blog/new-in-symfony-2-7-the-new-asset-component

+2
source

All Articles