Category Archives: assetic

Apache2 deflate encoding not working with Symfony2 assetic

I tried to enable mod_deflate for apache2. In my test environment all looks good. By an requested css or js file which is combined with assetic the Response Header is:

Cache-Control: private, must-revalidate
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/css; charset=UTF-8
Date: Thu, 11 Jun 2015 07:18:31 GMT
Etag: "232418785970289e0f97fbcfc791319e-gzip"
Expires: Thu, 11 Jun 2015 07:18:32 GMT
Keep-Alive: timeout=5, max=100
Last-Modified: Tue, 31 Mar 2015 11:22:45 GMT
Server: Apache/2.4.7 (Ubuntu)
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Powered-By: PHP/5.5.9-1ubuntu4.9
X-UA-Compatible: IE=Edge,chrome=1

But in the production environment the Response Header is:

Cache-Control: private, must-revalidate
Connection: Keep-Alive
Date: Thu, 11 Jun 2015 07:07:53 GMT
Expires: Thu, 11 Jun 2015 07:07:53 GMT
Keep-Alive: timeout=5, max=99
Server: Apache/2.2.22 (Debian)

Assetic combines this javascripts file to one. Here the deflate doesnt work

{% javascripts 
    <script src="{{ asset_url }}"></script>
{% endjavascripts %}

But in this case deflate works:

<script src="{{ asset('bundles/FMS/bootstrap/js/bootstrap.min.js') }}" type="text/javascript"></script>

now the response header from the production environment is

Accept-Ranges: bytes
Cache-Control: max-age=2592000
Content-Encoding: gzip
Content-Length: 7679
Content-Type: application/javascript
Date: Thu, 11 Jun 2015 07:07:42 GMT
Expires: Sat, 11 Jul 2015 07:07:42 GMT
Last-Modified: Wed, 17 Sep 2014 11:35:51 GMT
Server: Apache/2.2.22 (Debian)
Strict-Transport-Security: max-age=15768000
Vary: Accept-Encoding
X-UA-Compatible: IE=Edge,chrome=1

How can i get deflating to work with assetic combined css/js files in my production environment?

Assets with or without Assetic in Symfony2 are driving me crazy

I am having a problem with my project assets when deploying them in a shared hosting. The point is that on my development server, I can create virtual host without any problems but in the shared hosting I have not this possibility when more I can create a subdomain and point it to the web project folder.

In my local server I created a virtual host and pointing to /var/www/html/tanane and I access trough URL as tanane (ServerName) but in a shared hosting but this varies a bit and the content of the project is inside a subfolder in the root path, for example: /public_html/tanane and I reach it from the Apparently this is causing a issue and assets are lost and many fail to load, mostly those with sources like Twitter Bootstrap and FontAwesome. I have tried everything as you can see in this post but I have not accomplished anything yet.

This is what I did til now:

  • Try this syntax {{ asset('/bundles/css/somecss.css') }} works for some but others not, example.

    Problem: The CSS rule

    .contactenos, .contactenos:hover, .e-shop, .e-shop:hover, .faq, .faq:hover, .fctjur, .fctjur:hover, .fctnat, .fctnat:hover, .vendidos, .vendidos:hover {
        background: url(/bundles/template/images/sprites.png) no-repeat;

    works fine on local server but in shared hosting I need to change to:

    .contactenos, .contactenos:hover, .e-shop, .e-shop:hover, .faq, .faq:hover, .fctjur, .fctjur:hover, .fctnat, .fctnat:hover, .vendidos, .vendidos:hover {
        background: url(/tanane/web/bundles/template/images/sprites.png) no-repeat;

    Which not works at local server then.

    • As the post I leave shows, I tried a lot of things with Assetic without success. Can anyone suggest me something else? Perhaps something in .htaccess or some other place? Any help, advice?