C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
They can include static resources in your ASP.NET website project. We explore details of server-side-include use and processing in ASP.NET pages.
Intro. First, SSI is not an ASP.NET technology, but server-side includes are supported on IIS. The following comment, in an ASP.NET aspx file, will tell the server (IIS) to insert the text of the file Style1-min.css where the HTML comment is.
The example snippet shows the "file" attribute. It points directly to the file "Style1-min.css" that is located in the Style folder at the root of the web project, relative to the page.
Also: The other option you can add to the #include is virtual, which uses virtual paths.
Include example <!-- #include file="Style/Style1-min.css" -->
Uses. SSI directives are not great for many situations. Use them only for including static resources into .aspx pages. I decided on SSI as a good solution. I used it for including CSS markup into HTML headers.
Note: These CSS files needed to be minified, and the #include can include the minified files.
And: In the resulting HTML, a style tag will contain the contents of Style1-min.css. The IIS server, not ASP.NET, handles SSI.
SSI statement example <style type="text/css"><!-- #include file="Style/Style1-min.css" --></style>
Differences. SSI is essentially a macro that can greatly ease development effort on our part. You can duplicate SSI with a web user control. But that is much bulkier and is likely much slower. Here we examine some differences.
I investigated SSI. Microsoft provides a solid foundation article. I learned that the file system cache on IIS can make SSI extremely fast, and that by bypassing managed code, it is hard to beat performance-wise.
Dynamically Include Files: microsoft.com
SSI differences Lines of code: SSI: 1 ASP.NET control: More than 20 Caching: SSI: File system cache on IIS7 ASP.NET control: Memory or output cache Control tree: SSI: Literal controls added ASP.NET control: Custom controls added Assemblies: SSI: 0 ASP.NET control: One assembly Managed code: SSI: None ASP.NET control: All
Styles. Minified style sheets are basically "compressed" CSS, which is important for performance of a site. I have shown the include before. This code shows how to insert a preprocessed style sheet into a style tag in HTML (an aspx file).
Inline style sheets <%-- Style tags in an ASPX page's head element. --%> <style type="text/css"><!-- #include file="Style/Style1-min.css" --></style> <style type="text/css"><!-- #include file="Style/Style2-min.css" --></style>
Summary. We used SSI to optimize performance on both client and server. The example here results in a simpler control tree for ASP.NET. It will yield a smaller page for browsers that download the resource.
And: This enhances modularity. File-caching on IIS alleviates any overhead of SSI.