4

Assetic management is the hardest part to understand IMHO, even after playing a year or more with Symfony. Anyways, I was experimenting with named assets:

assets:
    mybundle_front_js:
        inputs:
            - @MeMyBundle/Resources/public/jquery/dist/jquery.js
            - @MeMyBundle/Resources/public/bootstrap/js/affix.js
            - @MeMyBundle/Resources/public/bootstrap/js/alert.js
            - @MeMyBundle/Resources/public/bootstrap/js/button.js
            - @MeMyBundle/Resources/public/bootstrap/js/carousel.js
            - @MeMyBundle/Resources/public/bootstrap/js/collapse.js
            - @MeMyBundle/Resources/public/bootstrap/js/dropdown.js
            - @MeMyBundle/Resources/public/bootstrap/js/modal.js
            - @MeMyBundle/Resources/public/bootstrap/js/tooltip.js
            - @MeMyBundle/Resources/public/bootstrap/js/popover.js
            - @MeMyBundle/Resources/public/bootstrap/js/scrollspy.js
            - @MeMyBundle/Resources/public/bootstrap/js/tab.js
            - @MeMyBundle/Resources/public/bootstrap/js/transition.js
        filters: [?uglifyjs2]

Using the named asset:

{% block javascripts %}
    {% javascripts
        "@mybundle_front_js" %}
        <script src="{{ asset_url }}"></script>
    {% endjavascripts %}
{% endblock %}

Dumping them:

php app/console cache:clear --env=prod
php app/console assetic:dump --env=prod

Result is two files, same size same content:

%kernel.root_dir%/../web/assetic/mybundle_front_js.js
%kernel.root_dir%/../web/js/055a364.js

Is there any reason to produce two identical files in prod environment?

gremo
  • 47,186
  • 75
  • 257
  • 421
  • This is also good for debugging, try using `--no-debug`, not sure but should prevent the `/assets` folder from being generated... but just a guess. – Markus Kottländer Apr 05 '14 at 01:48

1 Answers1

2

The first file assetic/mybundle_front_js.js is the resulting file from configuring the named asset. The second file is the resulting file used from the assetic block inside your template.

If you would use two assets in your assetic block:

{% block javascripts %}
    {% javascripts
        "@mybundle_front_js"
        "@whateveer" %}
        <script src="{{ asset_url }}"></script>
    {% endjavascripts %}
{% endblock %}

you would end up with two named assets files in the assetic/ folder, and one file in the js/ folder containing the contents of the both files.

Guessing why there are also the files in the assetic/ folder: You can configure named assets and reference to them cleanly without using the {% javascripts %} block.

Emii Khaos
  • 9,983
  • 3
  • 34
  • 57