Avoid inline/embedded code !!!
Using external files is a classical Web Performance Optimization (references), but sometimes it's better to include your styles/scripts in the web page.
- you have small assets (a few KBs)
- the cost of making a request is greater (new DNS queries, mobile network, ..)
- you never expect return visitors (landing page, temporary campaign, ...)
Inliner is a small library on the top of Microsoft.Web.Optimization (aka asp.net Bundling & Minification), that allow you to embed your resources/bundles in a web page.
Install-Package Inliner
// BundleConfig
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
// _layout.cshtml
@Inliner.Styles.Render("~/Content/css")
// _layout.cshtml
@Inliner.Scripts.Render("~/Scripts/main.js")
// _layout.cshtml
@Inliner.Scripts.Render("~/Scripts")