title: Using Twig for dynamic Javascript files
body: <p>I'm working on a kind of dashboard mini site that has blocks with a certain functionality. Using symfony2 I have a dedicated route /instagram that gets an html fragment that shows all the images taken in our venue.</p>
  
  <p>I want to refresh this block every 10 minutes, so i need to run the following javascript, in a function with a setTimeout, omitted for clarity.</p>
  
  <pre><code>jQuery('.gallery').load("/instagram", function() {
      jQuery('.gallery').cycle({
          fx: 'fade'
      });
  });
  </code></pre>
  
  <p>This code is in "@KunstmaanDashboardBundle/Resources/public/js/instagram.js" that i run through Assetic for concatenation and optimization.</p>
  
  <pre><code>{% javascripts
      '@KunstmaanDashboardBundle/Resources/public/js/thirdparty/jquery-1.7.min.js'
      '@KunstmaanDashboardBundle/Resources/public/js/thirdparty/jquery.cycle.lite.js'
      '@KunstmaanDashboardBundle/Resources/public/js/*'
      filter='closure'
  %}
      &lt;script src="{{ asset_url }}"&gt;&lt;/script&gt;
  {% endjavascripts %}
  </code></pre>
  
  <p>This works, but i don't feel like this is an optimal approach because i have to hardcode the route in the load() function. To fix this i need to move the instagram.js content to the Twig template and change it to:</p>
  
  <pre><code>jQuery('.gallery').load("{{ path('KunstmaanDashboardBundle_instagram') }}", function() {
      jQuery('.gallery').cycle({
          fx: 'fade'
      });
  });
  </code></pre>
  
  <p>But this way i lose the optimization and separation from content benefits of Assetic. And our custom code is in the most need of this optimizing.</p>
  
  <p>So my question is, how can i combine Assetic Javascript (and css for that matter) with the Twig parser so i can put the code above in the instagram.js file and make it work :)</p>