Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bundle Minification not working when publishing WebForms App

I'm trying to use bundle minification for some .css and .js files. My bundle config is the following:

public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/Modernizr").Include(
            "~/Scripts/modernizr.js"
        ));

        bundles.Add(new StyleBundle("~/TemplateContent").Include(
            "~/Content/bootstrap.css",
            "~/Content/bootstrap-responsive.css",
            "~/Content/prettyPhoto.css",
            "~/Content/prettify.css",
            "~/Content/flexslider.css",
            "~/Content/iview.css",
            "~/Content/style.css",
            "~/Content/default.css"
        ));

        bundles.Add(new StyleBundle("~/AppContent").Include(
            "~/Content/bootstrap-tablesorter.css",
            "~/Content/animate.css",
            "~/Content/font-awesome.css",
            "~/Content/jcarousel.css",
            "~/Conten/overwrite.css",
            "~/Content/sequence.css",
            "~/Content/sequence.ie.css",
            //more styles
        ));

        bundles.Add(new ScriptBundle("~/TemplateScripts").Include( 
            "~/Scripts/modernizr-*",
            "~/Scripts/jquery.js",
            "~/Scripts/raphael.js",
            "~/Scripts/jquery.easing.1.3.js",
            "~/Scripts/bootstrap.js",
            "~/Scripts/google-code-prettify/prettify.js",
            "~/Scripts/jquery.elastislide.js",
            "~/Scripts/jquery.tweet.js",
            "~/Scripts/jquery.prettyPhoto.js",
            "~/Scripts/jquery.flexslider.js",
            "~/Scripts/iview.js",
            "~/Scripts/jquery-hover-effect.js",
            "~/Scripts/animate.js",
            "~/Scripts/custom.js"
        ));

        bundles.Add(new ScriptBundle("~/AppScripts").Include(
            "~/Scripts/jquery.ticker.js",
            "~/Scripts/jquery.contenthover.js",
            "~/Scripts/jquery-ui-1.10.3.js",
            "~/Scripts/datetimepicker.js",
            "~/Scripts/jquery.metadata.js",
            //more scripts
        ));

        BundleTable.EnableOptimizations = true;
}

The problem happens when I publish the app to a server (godaddy shared web hosting), I do get a minified output, but I get 403 errors on those outputs.

If I set

BundleTable.EnableOptimizations = false;

The files are not minified but the page has the correct behavior.

like image 375
RainierMallol Avatar asked Nov 11 '13 14:11

RainierMallol


People also ask

What must be done to enable bundling and minification?

Bundling and minification is enabled or disabled by setting the value of the debug attribute in the compilation Element in the Web. config file. In the following XML, debug is set to true so bundling and minification is disabled. To enable bundling and minification, set the debug value to "false".

Can we use bundling and minification with ASP NET web forms like MVC?

To optimize the performance of an application I found that bundling and minification can significantly improve the performance. It can be applied on MVC as well as in ASP.NET web forms.

What is difference between bundling and minification?

Both bundling and minification are the two separate techniques to reduce the load time. The bundling reduces the number of requests to the Server, while the minification reduces the size of the requested assets.

How do you use bundling and minification in MVC 5?

Bundling and minification can be enabled or disabled in two ways: either setting the value of the debug attribute in the compilation Element in the Web. config file or setting the enableOptimizations property on the BundleTable class. In the following example, debug is set to true in web.


1 Answers

Turns out it was ASP.NET form authentication. As according to this, the name of the bundle should not be an existing directory. And well, forms authentication denies access to those directories that are not allowed int the web.config.

I did not know that the bundles create their own directory, so I basically added the location tag for those directories (even though they are not physically in the solution).

So basically...

For all of the previous bundles names, I added "~/bundles/" and then created the following location tag in the web.config:

<location path="bundles">
  <system.web>
    <authorization>
      <allow users="*"/>
    </authorization>
  </system.web>
</location>
like image 61
RainierMallol Avatar answered Oct 27 '22 04:10

RainierMallol