Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compress inline Javascript in twig

I would like to know if it is possible to compress via yui compressor in Symfony2 an inline javascript twig file.
the twig file contains js code as <script>/%JS code%/</script>
The doc states that it works for .js files but didn't mention the inline javascript

like image 780
Aysennoussi Avatar asked Apr 28 '14 13:04

Aysennoussi


Video Answer


1 Answers

Allow me to tell you how I finally did it:
Install the bundle : https://github.com/nibsirahsieu/SalvaJshrinkBundle
after that use the tag jshrink

<script type="text/javascript">{% jshrink %}
    $(document).ready(function() {
        // ...
    });
{% endjshrink %}</script>

PS: if you're not using symfony you can download the library: https://github.com/tedivm/JShrink

like image 187
Aysennoussi Avatar answered Sep 18 '22 09:09

Aysennoussi