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's rendered as 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);
}
The view itself:
<?php
header('Content-Type: application/javascript; charset=UTF-8', true);
?>(function(jQuery) {
// append stylesheets to <head>
var file;
// ...
})(jQuery);
I've found that I can use header()
in my view to add custom headers like X-Content-Type
as expected, however when I try to redefine the Content-Type
header it doesn't seem to do anything even with the replace
parameter set as true
.
I'm surely missing something obvious here, would appreciate your pointing it out to me :)
Thanks a lot for your help
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…