Search code examples
symfonycdnassetic

Symfony2 Assetic Generate URLs pointing to CDN


Is there a way I can extend Assetic so it will allow me to have it load my images from a CDN which I configure somewhere else. If I can write a plugin/extension/event listener/etc which allows fine-grain control, that would be awesome.

Likewise, are there any hooks for the assetic:dump console command which I could use so when I perform a dump I can automatically push images from the local box to the CDN (since I want the images to load locally on dev)?

Basically, I want to be able to have an images sitting somewhere in on my local machine, say: web/images/image.png

On dev, when I do something like:

asset('images/image.png')

It would spit out a URL like this on dev:

http://1.2.3.4/images/image.png

And on production it'd spit out something like:

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

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

Thanks.


Solution

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

    You can add a base url in your config.yml like:

    framework:
        templating:      
            assets_base_urls:
                http: my.cdn.net