locked
@Styles.Render vs in-line code RRS feed

  • Question

  • User-1416423428 posted

    I'm doing some reading... So if you have a _Layout.cshtml page, what's the advantage (if any) of using

    @Styles.Render("~/css") 

    as opposed to just 

    	  <link rel="stylesheet"    media="screen,print" href="~/css/bootstrap.css">
    	  <link rel="stylesheet"    type="text/css"      href="~/css/jquery-ui-1.8.16.css">
    	  <link rel="stylesheet"    type="text/css"      href="~/css/mysite.css">
    	  <link rel="stylesheet"    type="text/css"      href="~/css/mysite-media.css">

    Is @Styles.Render for MVC only, or will it work on a Webpages Razor project?

    How do you control which CSS gets loaded first? Sometimes the ordering of CSS is important. 

    Thursday, May 22, 2014 12:26 AM

Answers

  • User-821857111 posted

    Styles.Render() is available to Web Pages. It minifies the style sheets, thereby reducing their size and inproving download speeds (so long as your debug attribute in the compilation element in the web.config file is set to 'false'). You can read more about it here: http://www.mikesdotnetting.com/Article/197/Optimising-ASP.NET-Web-Pages-Sites-Bundling-And-Minification

    You can determine the order of css files through the order in which they are declared in the HTML, or added to a bundle if you are using the optimisation package. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 22, 2014 2:36 AM

All replies

  • User-821857111 posted

    Styles.Render() is available to Web Pages. It minifies the style sheets, thereby reducing their size and inproving download speeds (so long as your debug attribute in the compilation element in the web.config file is set to 'false'). You can read more about it here: http://www.mikesdotnetting.com/Article/197/Optimising-ASP.NET-Web-Pages-Sites-Bundling-And-Minification

    You can determine the order of css files through the order in which they are declared in the HTML, or added to a bundle if you are using the optimisation package. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 22, 2014 2:36 AM
  • User-1416423428 posted

    As always Mike, thanks for the answer... and your website! Lol, you're a mind reader - everything seems to be there already. 

    Thursday, May 22, 2014 3:22 AM