Search code examples
symfonytwigassetic

How to use Assetic with CacheBustingWorker and twig


As i can see Assetic made some progress on CacheBusting:
https://github.com/kriswallsmith/assetic#cache-busting

But i dont really understand how i should use this.
Can this be used from within twig:

{% stylesheets 'bundles/mybundle/css/fonts.css' 
               'bundles/mybundle/css/style.css'
               'bundles/mybundle/css/screen.css'
               filter='cssrewrite'
 %}
    <link rel="stylesheet" type="text/css" href="{{ asset_url }}" />
{% endstylesheets %}

And with the usual assetic:dump command?

Where would i have to hook the CacheBustingWorker in?


Solution

  • Cache buster is now part of symfony/AsseticBundle (Version >= 2.5.0).

    Change AsseticBundle version in composer.json like that:

    "symfony/assetic-bundle": "2.5.0",
    

    And activate cache busting for assets in your config.yml file like that

    assetic:
        workers:
            cache_busting: ~
    

    My JS files are now looking like that:

    web/bundles/js/projectname-876f9ee.js
    

    See https://github.com/symfony/AsseticBundle/pull/119#issuecomment-28877145