In Symfony2 I have a number of standard JavaScript files I include and compress into one file using the Twig YUI filter like so:
{% javascripts
'@WebIlluminationShopBundle/Resources/public/js/jquery.js'
'@WebIlluminationShopBundle/Resources/public/js/ui.js'
'@WebIlluminationShopBundle/Resources/public/js/tools.js'
'@WebIlluminationShopBundle/Resources/public/js/overlay.js'
'@WebIlluminationShopBundle/Resources/public/js/uniform.js'
'@WebIlluminationShopBundle/Resources/public/js/slider.js'
'@WebIlluminationShopBundle/Resources/public/js/global.js'
output='js/shop-compressed.js' filter='yui_js' %}
<script src="{{ asset_url }}" type="text/javascript"></script>
{% endjavascripts %}
Within my Twig templates I then include specific JavaScript Twig files, which have data passed to them as variables from the controller:
{% include 'SomeCompanySomeBundle:ControllerName:testScript.js.twig' with {'variable1': variable1, 'variable2': variable2} %}
Is there a way to compress this JavaScript like I would the main JavaScript files I use using the YUI filter?
It may not be possible, but just wondered if someone new for sure.
Twig generated JS files needs to be refreshed with Twig context on each request, son it’s not possible !