title: How to change Symfony2 Response Content-Type?
body: <p>This is my code </p>
  
  <pre><code>public function widgetAction(Request $request) {
      $response = new \Symfony\Component\HttpFoundation\Response(
              $this-&gt;renderView('WidgetoBundle:Widget:widget.html.twig'
      ));
      $response-&gt;headers-&gt;set('Content-Type', 'application/javascript');
      return $response;
  }
  </code></pre>
  
  <p>I'm using it as src of script i.e., <code>&lt;script ... src="{{ url_for_my_action }}" &gt;&lt;/script&gt;</code>.</p>
  
  <p>The problem is that on my localhost I'm getting a response with content type as it is in code (<strong>application/javascript</strong>). But, when I call it from server (1and1 shared hosting) the response is <strong>text/html</strong> type.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I've just moved my method to DefaultController from WidgetController and now content is correct application/javascript in both cases. No other changes. Same template used..
  Any idea why it is working now??</p>