How to make Laravel return a View's “Content-Type” header as “application/javascript”?

前端 未结 6 1316
-上瘾入骨i
-上瘾入骨i 2020-12-14 08:41

I\'m trying to output a dynamic javascript file for inclusion from external websites with the [script src=\"\"] tag. As the view is using the Blade engine, it\'

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-14 09:10

    In Laravel 5.4 you can do this:

    $contents = view('embedded')->with('foo', $foo);
    return response($contents)->header('Content-Type', 'application/javascript');
    

    BTW, there is no need to set the header in the view.

提交回复
热议问题