我正在try 输出一个动态javascript文件,以便从带有[script src=""]
标记的外部网站中包含它.由于视图使用Blade 引擎,因此渲染为text/html
.
I'd like the Content-Type
header to be set to application/javascript
for this view only to avoid Chrome bugging me with messages like "Resource interpreted as Script but transferred with MIME type text/html:
"
My controller:
{
// ...
return View::make('embedded')->with('foo', $foo);
}
视图本身:
<?php
header('Content-Type: application/javascript; charset=UTF-8', true);
?>(function(jQuery) {
// append stylesheets to <head>
var file;
// ...
})(jQuery);
我发现,在我的视图中,我可以使用header()
来添加自定义标题,如预期的X-Content-Type
,然而,当我try 重新定义Content-Type
标题时,即使replace
参数设置为true
,它似乎也没有任何作用.
我肯定错过了一些显而易见的东西,如果你能给我指出,我将不胜感激:)
非常感谢您的帮助