Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET bundling - default virtual paths?

As far as I can tell (because frankly documentation on System.Web.Optimization is very sparse), the way bundling works in ASP.NET is that you register a set of files (Javascript or CSS, corresponding with ScriptBundle and StyleBundle), and associate them with a virtual path; for example, ~/bundles/jqueryui for all the jQuery UI scripts. Later, ASP.NET can minify these files when you're running in non-debug mode, and the minified version will be made available at the virtual path you specified for the bundle.

The default bundle setup registers some script bundles with ~/bundles/... as the virtual path, and some CSS with ~/Content/css as the virtual path. My question is, isn't this inconsistent? Wouldn't it make more sense to have something like ~/bundles/js/... and ~/bundles/css/...? In fact, the ~/Content directory actually exists as a real directory, so there's even the chance of a name collision. I'd have thought you'd want your virtual bundle paths to be directories that don't exist by default, and are not meant to be created on the actual filesystem. Is there some reason why ~/Content/css is used for the CSS bundle virtual paths that I'm not understanding?

like image 793
Jez Avatar asked Oct 25 '12 09:10

Jez


1 Answers

Great question, and the short story is that in general it doesn't matter at all. However, some script files and CSS depend on their physical location on disk because they use relative paths to reference other content. For example, of you look at the default jQuery UI bundle in new ASP.NET 4.5 project you see it has a rather long path. That's because jQuery's CSS has relative references to some image files. To get those to resolve correctly the paths matter or else things like ".." will not go up to the right parent directory.

like image 94
Eilon Avatar answered Sep 21 '22 18:09

Eilon