最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Combining files to have only a single call for all CSS files with Assetic on Symfony 2 - Stack Overflow

programmeradmin0浏览0评论

I'm using assetic on Symfony 2 and I press all my CSS and JS files thanks to YUI. ALL works perfectly, but on prod environment, I have multiple calls to load every pressed files. In fact, I thought that assetic could bine all CSS files (and JS files) to have just a single call to a unique file (one for CSS, another one for JS), and that for each page, is it possible ?

I don't find documentation about it ... Have an idea ? Thanks !

I'm using assetic on Symfony 2 and I press all my CSS and JS files thanks to YUI. ALL works perfectly, but on prod environment, I have multiple calls to load every pressed files. In fact, I thought that assetic could bine all CSS files (and JS files) to have just a single call to a unique file (one for CSS, another one for JS), and that for each page, is it possible ?

I don't find documentation about it ... Have an idea ? Thanks !

Share Improve this question asked Nov 6, 2011 at 13:35 SybioSybio 8,6553 gold badges46 silver badges54 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Like describe in the documentation, you can also bine several files into one. This helps to reduce the number of HTTP requests, which is great for front end performance.

You just have to use this syntax :

{% javascripts
    '@AcmeFooBundle/Resources/public/js/*'
    '@AcmeBarBundle/Resources/public/js/form.js'
    '@AcmeBarBundle/Resources/public/js/calendar.js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}

For bining css files into one in dev environment

php app/console cache:clear --env=dev --no-debug

To see the bined file served when the page is requested

// app_dev.php
$kernel = new AppKernel('dev', false); 
// Setting the second parameter to false turns of debugging

Ensure you are bining assets

{% javascripts
    '@AcmeFooBundle/Resources/public/js/*'
    '@AcmeBarBundle/Resources/public/js/form.js'
    '@AcmeBarBundle/Resources/public/js/calendar.js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}

Same follows for production environment

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论