Google PageSpeed often suggests to optimize CSS delivery. It occurred to me that it would reduce network round trips to inline all the CSS like this:
<style type="text/css">
@{
var bootstrap = File.ReadAllText(Server.MapPath("bootstrap.min.css"));
var bootstrapTheme = File.ReadAllText(Server.MapPath("theme.min.css"));
var fontAwesome = File.ReadAllText(Server.MapPath("font-awesome.min.css"));
var bigfont = File.ReadAllText(Server.MapPath("bigfont.min.css"));
var bigfontPrint = File.ReadAllText(Server.MapPath("bigfont-print.min.css"));
}
@Html.Raw(bootstrap)
@Html.Raw(bootstrapTheme)
@Html.Raw(fontAwesome)
@Html.Raw(bigfont)
@Html.Raw(bigfontPrint)
</style>
This seems to be a reasonable solution to the problem of slow page loads and has increased my PageSpeed score to 95 from 88.
Putting code-style aside for the moment, what technical reasons, if any, exist for NOT in-lining all CSS in this way?
link
does this, however,link
could be, at some point by some vendor, cause the linked files to be loaded asynchronously. You could never do that with CSS content shoved into your HTML page. There's a reason script tags are delegated until last - the same logic applies to all content – A Red Herring 22 hours ago