Symfony Assetic - part_1 in url
Asked Answered
X

1

14

Okay so I've been searching all over for some input into this but haven't found anything to help directly (only mentions of this problem in relation to something else).

Basically I'm having problems with the path assetic generates when looking for an assetic file versus what is actually generated.

The path it's trying to load is: /js/admin_part_1.js whereas the file it is generating is simply /js/admin.js

I am dumping files with:

php app/console assetic:dump --env=prod --no-debug

Relevant portion of the config.yml:

assetic:
debug:          "%kernel.debug%"
use_controller: false
filters:
    cssrewrite: ~
assets:
    admin_js:
        inputs:
            - @UserBundle/Resources/js/admin-tools.js
        output: js/admin.js

Loading the javascript tag via:

{% javascripts '@admin_js' output='js/admin.js' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

My question is, where is this phantom _part_1 coming from and how can I tell it stop adding it in?

Xenomorphic answered 27/9, 2013 at 17:59 Comment(4)
Do you need to specify the output path in both the config.yml and your twig template?Hubbell
The template section is telling twig where to find the file (if I leave it out in the template it defaults to something like d434123.js). The one on the config tells assetic where to dump the file to begin with.Xenomorphic
Did you ever figure this out? Same problem here. getTargetPath() doesn't contain the _part_1 but the actual file names do!Emmet
Just did. In my case for some reason another developer turned on dev mod in app.php via $kernel = new AppKernel('prod', true); - I since removed the ,true line but you could also get around it by getting rid of the --no-debug flag on the dump command.Xenomorphic
E
0

I guess this is used to version files. Even if in your code you see assets/css/my_file.css and in rendered HTML you see assets/css/my_file.09280929.css, Assetic know which is the file to take. Normally, generated in public/assets/mybundle/....

Assetic will generate a file with a kind of hash that will be store in cache.

But next time, if the assets change, then the hash will change and that will allow automatic cache refresh.

You could disable it if you really want by changing config read_from and write_to to null:

assetic:
    read_from: ~
    write_to: ~

And by adding versionning to null in the template where you call your asset file:

<link rel="stylesheet" href="{{ asset('css/my_file.css', version=null) }}" />
Ensile answered 5/11, 2023 at 14:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.