hbogert
hbogert

Reputation: 4353

Make Assetic output conventional links

Is it possible to mimic "normal" assets using Assetic so that the following:

{% javascripts '@AppBundle/Resources/public/js/*' %}
  <script src="{{ asset_url }}"></script>
{% endjavascripts %}

Would become,

<script src="bundles/App/js/1.js"></script>
<script src="bundles/App/js/2.js"></script>

-- if it is a given that 1.js and 2.js are in '@AppBundle/Resources/public/js/*'

The latter, instead of what it becomes currently in Assetic's debug mode:

<script src="/dev.php/js/w/aaaaa_1.js"></script>
<script src="/dev.php/js/w/aaaaa_2.js"></script>

Basically, in development, I want to be able to retrieve the assets directly from the webserver, without using,

  1. Symfony's controller to serve the content (as it adds 1-2s per asset -- even for small files)
  2. the $ php bin/console assetic:watch (as it uses a lot of CPU on our shared development server)
  3. Manually dump after each asset change.

Upvotes: 0

Views: 32

Answers (1)

tmas
tmas

Reputation: 442

I think you should be able to do this:

{% javascripts 'bundles/app/js/*' %}
    <script src="{{ asset_url }}"></script>
{% endjavascripts %}

And use the command assets:install --symlink

in the config_dev.yml

assetic:
    use_controller: false

However using the @ notation resolves caching issues when you deploy since the name will be different when the content changes causing browsers to be forced to download the new file.

More information in the documentation.

Upvotes: 1

Related Questions