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