symfonyasseticsymfony3symfony-3.4

Symfony3 & Assetic : different behavior in dev or prod


I'm working on Symfony 3.4 and Assetic. Let's say my website is www.mycompany.com and i'm using 2 particular types of asset :

When i visit my website in dev mode www.mycompany.com/app_dev.php/ :

When i visit my website in prod mode www.mycompany.com/ :

Why this behavior ? For your information, i use Assetic this way to load myu assets :

{% stylesheets '@PimInterfaceBundle/Resources/public/css/*' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

// Same for JS

Thanks.


Solution

  • When using the cssrewrite filter, don't refer to your CSS files using the @XxBundle syntax.

    try this

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

    here is doc

    1. Including CSS Stylesheets

    2. Fixing CSS Paths with the cssrewrite Filter

    3. Dumping Asset Files in the prod Environment

    if this is not working for you then try php bin/console asset:install

    in prod php bin/console assetic:dump --env=prod --no-debug `