Question

If i do

//BundleConfig.cs

bundles.Add(new ScriptBundle("~/Scripts/Home").Include("~/Scripts/Home/Home.js"));

//index.cstml

@section scripts
{
    @Scripts.Render("~/Scripts/Home")
}

then the script is not going to get rendered in release mode, it works fine in debug mode without

BundleTable.EnableOptimizations = true;

but if i do

//BundleConfig.cs

bundles.Add(new ScriptBundle("~/bundles/Home").Include("~/Scripts/Home/Home.js"));

//index.cstml

@section scripts
{
    @Scripts.Render("~/bundles/Home")
}

then it works fine in both debug and release mode.

Is Scripts/Home a reserved name or something?

Note: I do not have anything else named ~/Scripts/Home in BundleConfig.cs

Was it helpful?

Solution

Not Scripts/Home in particular but it must be a valid bundle name, or path to an actual file.

For example if you were to add the following to your View without adding the appropriate bundle name it would actually render the script directly from disk to the browser. (yay)

@Scripts.Render("~/scripts/jquery-1.8.2.js")

But any reference to a non existent file or bundle name would cause an error, like these:

@Scripts.Render("~/scripts/jquery/*.*") -- error, no wildcards either
@Scripts.Render("~/non-existant-directory-or-bundle-name") -- error
@Scripts.Render("~/scripts/no-such-file.js") -- error

OTHER TIPS

No, however the bundle name (~/Scripts/Home) cannot match either an existing folder or file. For this reason, I leave my scripts in ~/Scripts/... but name the bundles ~/js/....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top