Search code examples
javascriptphpsymfonyassetic

Symfony2 Assetic not working with multiple javascript file with the * sign


I use Symfony2 and the assetic Bundle. (probleme when using the * sign to ask assetic to take all files)

Form what I have read here and there assetic allow to use multiple javascript file.

This work just fine when when I write all the file right before the <'/html> tag:

{% javascripts
    '@MySiteBlogBundle/Resources/public/js/test1.js' 
    '@MySiteBlogBundle/Resources/public/js/test2.js'
    '@MySiteBlogBundle/Resources/public/js/test3.js' 
%}
    <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}    

but the same code, doesn't work if instead of listing the file, I use the * (just like this:)

{% javascripts
    '@MySiteBlogBundle/Resources/public/js/*'
  %}
    <script type="text/javascript" src="{{ asset_url }}"></script>
 {% endjavascripts %}

with the *, it works only depending on the pages which are displayed. I did all my javascipt test on class which are on my main twig template. And thoses class are displayed on all pages... So all test should be working.

Anyone ever had such probleme when using this * sign with assetic?

Thanks for any comment/help.


Solution

  • I noticed only two problems with assetic earlier.

    First, in production mode you have to dump them (php app/console assetic:dump --env=prod) before using. Okay, this is not a problem but you shouldn't forget it.

    Second, if you use the * sign to load all JavaScripts then the order of your scripts will be alphabetical and this can break a few dependencies among script files. This is the reason I usually don't use the * sign.