c# - Bundling javascript files in MVC 4.0 -


i'm trying bundle javascript files in web application increase performance. i'm trying load minified version of jquery example when run web application jquery not loaded.

bundle config:

  public class bundleconfig     {         public static void registerbundles(bundlecollection bundles)         {             bundles.add(new scriptbundle("~/bundles/jquery").includedirectory("~/scripts/","jquery-1.8.2.min.js")); //also tried this: //bundles.add(new scriptbundle("~/bundles/jquery").include("~/scripts/jquery-1.8.2.min.js"));             bundles.add(new stylebundle("~/content/css").include("~/content/site.css"));         }     } 

master page:

@using system.configuration <!doctype html> <html> <head>     <meta charset="utf-8" />     <meta name="viewport" content="width=device-width" />     <meta name="apple-mobile-web-app-capable" content="yes">     <title>@viewbag.title</title>     @styles.render("~/content/css")        <script type="text/javascript">         var screenrefreshtime = '@configurationmanager.appsettings["screenrefreshtime"].tostring()';         screenrefreshtime = parseint(screenrefreshtime);     </script> </head> <body>     @renderbody()     @scripts.render("~/bundles/jquery")     @rendersection("scripts", required: false) </body> </html> 

you no need include min when create bundle it.i assuming have jquery.1.8.2.js , jquery.1.8.2.min.js in same folder , file names same except "min" word ex: jquery.1.8.2.js,jquery.1.8.2.min.js. instead of include directory can try direct include working fine. code this

  public class bundleconfig   {     public static void registerbundles(bundlecollection bundles)     {          bundles.add(new scriptbundle("~/bundles/jquery").include("jquery-1.8.2.js"));      } } 

also need mention bundling works on release mode if need check on debug mode need enable optimizations.

bundletable.enableoptimizations = true; 

to call it

 @scripts.render("~/bundles/jquery") 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -