2

This is just a trivial annoyance and by no means a major issue, but when using the bundling feature of ASP.NET MVC 4 the output contains minimal white space. eg

Rendered manually:

<head>
    <title>Example page</title>
    <meta name="example" content="blah blah"/>
    <meta name="example2" content="blah blah"/>
    <link href="/css1.css" rel="stylesheet"/>
    <link href="/css2.css" rel="stylesheet"/>
    <link href="/css3css" rel="stylesheet"/>         
    <script src="/script1.js"></script>
    <script src="/script2.js"></script>
    <script src="/script3.js"></script>
    <link rel="shortcut icon" href="/favicon.ico">   
</head>
<body>
    ....

Rendering links and stylesheets wtih bundling:

<head>
    <title>Example page</title>
    <meta name="example" content="blah blah"/>
    <meta name="example2" content="blah blah"/>
    <link href="/css1.css" rel="stylesheet"/>
<link href="/css2.css" rel="stylesheet"/>
<link href="/css3css" rel="stylesheet"/>         
    <script src="/script1.js"></script>
<script src="/script2.js"></script>
<script src="/script3.js"></script>
    <link rel="shortcut icon" href="/favicon.ico">   
</head>
<body>
    ....

At the end of the day it's just whitespace and doesn't affect the user experience but the perfectionist in me still cringes when I see it. How can I, for example, force each item output by bundling to be prefixed with an arbitrary number of tabs?

nathanchere
  • 8,008
  • 15
  • 65
  • 86
  • 1
    What you are talking about is not a problem with bundling... since your scripts aren't even bundled in this case. See [this prior post](http://stackoverflow.com/questions/14586562/getting-styles-render-to-preserve-indentation-from-razor-template/14594452#14594452). – MikeSmithDev Jun 03 '13 at 15:18

1 Answers1

2

The line

@Scripts.Render("~/bundles/jquery")

Will call a method that returns a IHtmlString.

So you can do this:

@{
    var scripts = Scripts.Render("~/bundles/jquery");
    scripts = new HtmlString(scripts.ToString().Replace("<script", "    <script"));
}

@scripts
BrunoLM
  • 97,872
  • 84
  • 296
  • 452