Symfony2 and Assetic - cssrewrite works perfectly for dev, not for prod
Asked Answered
B

4

8

I include my CSS with the following code:

{% stylesheets 'bundles/majorproductionssewingdivasite/css/*.css' filter='cssrewrite' %}
    <link rel="stylesheet" type="text/css" href="{{ asset_url }}" />
{% endstylesheets %}

In dev, this allows me to use image sprites without any problems. The resulting URL to my sprite is:

http://localhost/diva/web/bundles/majorproductionssewingdivasite/images/diva-sprites.jpg

But, in prod, it gets mapped to:

http://localhost/diva/bundles/majorproductionssewingdivasite/images/diva-sprites.jpg

Notice the lack of web directory.

The generated code in the CSS file is as it should be, and all my CSS (both the dev 'chunks' and the finalized prod assetic dump) are at web/css/. Any ideas as to why the prod environment is skipping the web directory?

EDIT: what's weird is that both dev and prod generate the same URL in the CSS itself:

url('../../bundles/majorproductionssewingdivasite/images/diva-sprites.jpg')

Bluebeard answered 28/12, 2012 at 17:12 Comment(0)
B
20

Solution is to dump the assets in the prod environment:

$ app/console assetic:dump --env=prod
Bluebeard answered 28/12, 2012 at 17:50 Comment(2)
This is the correct answer. But you may need to clear the cache first too php app/console cache:clear --env=prod. Dumping the asset files before cleaning the cache didn't resolve the problem for me. I'm a bit new to Symfony2, but from what I've just experienced, it seems to dump the asset files from the cache, not from the physical files.Glacis
OMG how i can miss this @_@Cirone
G
9

Remember to Clear the Cache

php app/console cache:clear --env=prod --no-debug

berore

php app/console assetic:dump --env=prod --no-debug
Gluteus answered 13/9, 2013 at 15:28 Comment(0)
P
2

Also remember to appropriate configure assetic, in your config_prod.yml set as below:

assetic:
    use_controller: false

Edit: As said in Symfony docs (actually in chapter refers to dev environment): tell Symfony to stop trying to process these files dynamically

Plugboard answered 2/10, 2017 at 8:54 Comment(2)
Please include some extra details in order to make your reply completeHollyhock
You are right, but usual configuration is already use_controller: '%kernel.debug%'Palish
T
0

In debug mode, Assetic 1.1 also seems to rewrite CSS even when it's not in the {% stylesheets %} tag. So it's worth checking that's there when you turn off debug in production.

Tito answered 15/1, 2013 at 5:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.