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')

Major Productions
  • 5,914
  • 13
  • 70
  • 149

4 Answers4

20

Solution is to dump the assets in the prod environment:

$ app/console assetic:dump --env=prod
Major Productions
  • 5,914
  • 13
  • 70
  • 149
  • 7
    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. – cartbeforehorse Aug 09 '13 at 09:58
  • OMG how i can miss this @_@ – GusDeCooL Oct 21 '14 at 07:12
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
rjmunro
  • 27,203
  • 20
  • 110
  • 132
Fernando
  • 91
  • 1
  • 1
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

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.

Ryan
  • 4,594
  • 1
  • 32
  • 35