-->

Assetic not creating combined links

2019-02-15 09:58发布

问题:

Just having a few problems trying to get Assetic to generate the combined links in rendered webpages. The files themselves are being generated fine, but in the web page in the production environment, I'm continuing to see the seperate file URLs (which do not work in production, as those uncombined files aren't available).

In a template, I have:

{% stylesheets
    '@TBundle/Resources/public/css/bootstrap/bootstrap.css'
    '@TBundle/Resources/public/css/bootstrap/bootstrap-responsive.css'

    '@TBundle/Resources/public/css/jquery-selectbox/jquery.selectBox.css'
%}
    <link href="{{ asset_url }}" rel="stylesheet" media="screen" />
{% endstylesheets %}

In production, this is still rendered as:

<link href="/css/2f787d0_bootstrap_1.css" rel="stylesheet" media="screen" />
<link href="/css/2f787d0_bootstrap-responsive_2.css" rel="stylesheet" media="screen" />
<link href="/css/2f787d0_jquery.selectBox_3.css" rel="stylesheet" media="screen" />

Despite that, when I invoke php app/console assetic:dump --env=prod I get:

11:13:43 [dir+] /var/www/tbundle/app/../web/css
11:13:43 [file+] /var/www/tbundle/app/../web/css/2f787d0.css

I'm using the default Assetic settings from Symfony2. Any thoughts on what might be causing this?

回答1:

I had this exact same problem, and for me the issue was in my app.php file. I was loading the kernel as follows:

$kernel = new AppKernel('prod', true);

It appears as though this caused the function to not run in debug mode and combine the assets. When i changed the second argument to false, the assets successfully combined on production and remained uncombined on dev:

$kernel = new AppKernel('prod', false);

Also, you can pass combine=true as an argument to explicitly request that the assets get combined just to test that this functionality is working properly.