Symfony assetic doesn't work properly - symfony

I have problem with assetic in symfony. Stylesheet part does not work at all in dev environment (css styles are not applied to the document) and in production environment everything is ok except resources are not linked correctly for fontawesome
I am using bower and my .bowerrc file:
{
"directory": "src/Acme/AdminBundle/Resources/public/3rdparty"
}
My config.app file:
assetic:
debug: "%kernel.debug%"
use_controller: true
bundles: ["AcmeAdminBundle"]
filters:
cssrewrite: ~
yui_css:
jar: "%kernel.root_dir%/../bin/yuicompressor.jar"
yui_js:
jar: "%kernel.root_dir%/../bin/yuicompressor.jar"
and finally the layout.html.twig
{% stylesheets filter='cssrewrite,yui_css' output='css/3rdparty.css'
'#AcmeAdminBundle/Resources/public/3rdparty/bootstrap/dist/css/bootstrap.css'
'#AcmeAdminBundle/Resources/public/3rdparty/fontawesome/css/font-awesome.css'
%}
<link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}
output

This is a known issue that causes the cssrewrite filter to fail when using the #AcmeFooBundle syntax for CSS Stylesheetsdocument.
In other words, you can't use #AcmeFooBundle and cssrewrite filter together.

Related

Symfony2 Assetic: duplicates combined content of JS files in dev environment

I have set up assets in my config.yml:
assetic:
debug: '%kernel.debug%'
use_controller: '%kernel.debug%'
filters:
cssrewrite: ~
On twig template JS files are loaded:
{% block javascripts %}
{% javascripts output="assets/js/app.js"
'#AppBundle/Resources/public/js/thirdparty/jquery-3.1.1.min.js'
'#AppBundle/Resources/public/js/thirdparty/bootstrap.min.js'
'#AppBundle/Resources/public/js/thirdparty/bootstrap-select.min.js'
'#AppBundle/Resources/public/js/forms.js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
The issue is: In dev environment there are 4 separate requests to these files, but each one is combined with others (what should be done ONLY in prod environment):
Seems like some misconfiguration, but have no idea what exactly.
P.S. In prod environment eveything OK - there is only 1 request for combined file.
P.S.S. Symfony version is 2.8.12
Solved by reinstalling symfony/assetic-bundle.
Still have no idea what was wrong.

UglifyJS and UglifyCSS Symfony2 assetics

I have some troubles making UglifyCSS and UglifyJS works with Assetics on my Symfony2.6 app.
I simplified a little the problem for the moment (I properly checked that I still meet the issue with this config). I import my stylesheet in my base twig file like this:
{% stylesheets
'#main_css'
output='assets/app.min.css'
%}
<link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}
My assetic is configured with the UglifyCSS and with the filters cssrewrite and uglifycss. The filters are configured be applied to all .css files.
Here is my configuration:
# app/config/config.yml
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: ['MyFrontBundle']
node: /usr/local/bin/node
node_paths:
- "%kernel.root_dir%/../node_modules"
- "/usr/local/lib/node_modules"
filters:
cssrewrite:
apply_to: "\.css$"
uglifycss:
bin: %kernel.root_dir%/../node_modules/.bin/uglifycss
apply_to: "\.css$"
# uglifyjs2:
# bin: %kernel.root_dir%/../node_modules/.bin/uglifyjs
# apply_to: "\.js$"
assets:
main_css:
inputs:
- '#MyFrontBundle/Resources/public/css/app.min.css'
Here is the error:
$ php app/console assetic:dump
Dumping all dev assets.
Debug mode is on.
18:52:42 [file+] /path/to/app/../web/assetic/main_css.css
[Symfony\Component\Process\Exception\RuntimeException]
The process has been signaled with signal "6".
assetic:dump [--forks="..."] [--watch] [--force] [--period="..."] [write_to]
If I comment the uglifycss filter in my config, there is no longer any problem. Also, if I apply the filter directly into the stylesheet block, there is no problem too. So the problem comes from the apply_to declaration but I don't see why.
Oh yeah, I tried too by adding the filter manually the filter to the stylesheet block:
{% stylesheets
'#main_css'
filter="?uglifycss"
output='assets/app.min.css'
%}
<link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}
And then everything works fine. So in the ends it really comes down to using the apply_to to apply the filter.
I have exactly the same problem with uglifyjs. I checked beforehand all the paths: node, bin to uglify.
Thanks.

Symfony2 extremely slow loading pages

Guys i have problem in dev env. My page loading is extremely slow, after refreshing page i must wait 10-15 sec. I just try to show page without any database query just simple html/css layout, MS is 8-10k+ (10000+ ms). I have installed APC and disable automatic assetic generation in config.yml
assetic:
debug: "%kernel.debug%"
use_controller: false
#bundles: ['ISLabEcommerceBundle']
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
This only happens when I use assets for my css files. When i disable assets and dont load css files from web dir all pages is loaded to fast.
{% stylesheets 'bundles/islabecommerce/css/*' filter='cssrewrite' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
Could not work under this environment
Any tip how can i incres loading speed ?
I suggest dumping your assets. You can read about it in symfony2 documentation

Unable to use filter uglifyjs in assetic without having a segfault

It seems that i can't use uglifyjs filter with assetic on a Symfony2 context, as it seems to cause segmentation fault.
php app/console assetic:dump
Dumping all dev assets.
Debug mode is off.
16:35:02 [file+] ...../../web/css/compiled_50f84d1.css
16:35:02 [file+] ...../../web/js/compiled_e371e27.js
Segmentation fault: 11
My config looks like :
assetic:
debug: false
use_controller: false
read_from: %kernel.root_dir%/../web
write_to: %kernel.root_dir%/../web
bundles: [] # disable bundles parsing
node: /usr/local/bin/node
filters:
cssmin: ~
uglifyjs: ~
And my view :
{% javascripts 'js/all.js' 'js/player.js' filter='uglifyjs' output='js/compiled_*.js' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
As soon as i disable the filter I no longer have the error. I have a fresh install of node and I have uglify-js#1.3.3 node_modules/uglify-js
I don't know if this will help you, but this is how I've setup uglifyjs in my config_prod.yml to make it work in production only:
assetic:
filters:
uglifyjs:
bin: /usr/local/bin/uglifyjs
no_copyright: true
apply_to: ["\.coffee$", "\.js$"]
Thanks to apply_to you don't need to use filter='uglifyjs' in the {% javascripts ... %} tag.

Symfony 2 + Assetic Runtime Java Error

I'm trying to set my Symfony 2 project to combine and compress a number of javascript files. Below is an example of the tag I'm using to accomplish this:
{% javascripts 'bundles/acmedemo/js/*' output='js/plugins.js' filter='closure' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
I've config to map to the yui compressor jar.
assetic:
debug: %kernel.debug%
use_controller: false
filters:
cssrewrite: ~
closure:
jar: %kernel.root_dir%/java/yuicompressor-2.4.6.jar
yui_css:
jar: %kernel.root_dir%/java/yuicompressor-2.4.6.jar
When I try to bring up the page in the browser it takes a while to load and doesn't include the output file. I tried to run the app/console assetic:dump command and got this error:
[RuntimeException]
If no input file is specified, it defaults to stdin. In this case, the 'type' option is required. Otherwise, the 'type' option is required only if the input. And the windows prompt cuts it off.
Has anyone else encountered this issue?
Is you yuicompressor file actually located in %kernel.root_dir%/java/yuicompressor-2.4.6.jar ? not %kernel.root_dir%/Resources/java/yuicompressor-2.4.6.jar ?
Check this link, maybe something will help http://groups.google.com/group/symfony2/browse_thread/thread/dde8b418813bab37/1d4e42a7396f2e0f?lnk=gst&q=yui
Additionaly: the path has to be put in: ""
The config will look like this:
assetic:
debug: %kernel.debug%
use_controller: false
filters:
cssrewrite: ~
closure:
jar: "%kernel.root_dir%/java/yuicompressor-2.4.6.jar"
yui_css:
jar: "%kernel.root_dir%/java/yuicompressor-2.4.6.jar"
The following isn't an error as such but you seem to be configuring the YUI compressor from Yahoo as 'closure'. Google Closure is a different JS compression tool.

Resources