Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to have a file extension in a bundle name?

I would like to have define a bundle like this:

bundles.Add(
    new StyleBundle("~/style.css").Include(
        //...
));

If the bundle name is just "~/style" this works, but with the file extension it always returns a 404. I suspect the server searches for CSS and JS files on the drive and ignores the bundling system, but I can't find anyone else who is trying to include file extensions in bundle names. Is this possible to do without something like a URL rewrite?

like image 576
sbking Avatar asked Oct 17 '12 09:10

sbking


People also ask

What is the extension bundle?

Extension bundles are a way to add a pre-defined set of compatible set of binding extensions to your function app. Extension bundles are versioned.

What is a .bundle file Mac?

Bundle file or plug-in that adds extra features to the operating system or an application in Mac OS X; examples include support for audio and video cards, custom printer filters, extensions for Dreamweaver, and additional effects in iMovie.

What is bundle config?

Bundling is a new feature in ASP.NET 4.5 that makes it easy to combine or bundle multiple files into a single file. You can create CSS, JavaScript and other bundles. Fewer files means fewer HTTP requests and that can improve first page load performance.

What are the types of files we can bundle in bundle config?

How to add files in BundleConfig. There you see two type of bundle class, StyleBundle and ScriptBundle , Now you can create as many instance as you need of any of those classes and the finally add to BundleCollection. remember BundleCollection class will reamin always one only.


1 Answers

You could add the following to your <system.webServer> section in web.config:

<modules runAllManagedModulesForAllRequests="true" />

This will ensure that requests for static resources such as .js and .css will pass through the managed modules and be intercepted by ASP.NET MVC.

As an alternative to enabling runAllManagedModulesForAllRequests for all requests you could configure them only for the urls you need to use. So inside the <handlers> add the following:

<handlers>
    <!-- ... -->
    <add name="scriptBundle" verb="*" path="script.js" type="System.Web.Optimization.BundleHandler, System.Web.Optimization" preCondition="managedHandler" />
    <add name="cssBundle" verb="*" path="style.css" type="System.Web.Optimization.BundleHandler, System.Web.Optimization" preCondition="managedHandler" />
</handlers>
like image 190
Darin Dimitrov Avatar answered Sep 23 '22 17:09

Darin Dimitrov