Archive for the ‘Symfony2’ Category

symfony2 assetic: unexpected extra files and how I dealt with them.

The first time I used assetic for symfony2, I got unexpected results. Assetic
seemed to be including more javascript files than I had in my js directory. I experienced
this on Ubuntu 12.04, and I use gedit as my editor.

Here was my js directory:

Here was my code:
{% javascripts ‘@AcmeHelloBundle/Resources/public/js/*’ %}
<script src=”{{ asset_url }}”></script>
{% endjavascripts %}

My expected result:

<script src=”/production/Symfony/web/app_dev.php/js/addff24_part_1_one_1.js”></script>
<script src=”/production/Symfony/web/app_dev.php/js/addff24_part_1_three_2.js”></script>
<script src=”/production/Symfony/web/app_dev.php/js/addff24_part_1_two_3.js”></script>

My actual result:
<script src=”/production/Symfony/web/app_dev.php/js/addff24_part_1_one_1.js”></script>
<script src=”/production/Symfony/web/app_dev.php/js/addff24_part_1_one_2.js”></script>
<script src=”/production/Symfony/web/app_dev.php/js/addff24_part_1_three_3.js”></script>
<script src=”/production/Symfony/web/app_dev.php/js/addff24_part_1_three_4.js”></script>
<script src=”/production/Symfony/web/app_dev.php/js/addff24_part_1_two_5.js”></script>
<script src=”/production/Symfony/web/app_dev.php/js/addff24_part_1_two_6.js”></script>

So what happened? Why did assetic link to six files instead of three?¬† I went back to the directory and clicked “View -> Show Hidden Files”

Here are the six files that were actually in my directory:

To fix the problem, I deleted all the .js~ files, then ran the following commands:

Cleared my symfony cache:
sudo rm -rf app/cache/*

Regenerated the javascript cache:
sudo  php app/console assetic:dump

Problem solved.

Categories: Symfony2