javascript - Adding additional files to C# script and css bundles -


ok have been using c# bundling minify , combine scripts , css.

but i'm not sure how append script bundle has been created.

i'm trying append bundle because not scripts found in same file, i'm working nopcommerce solution in visual studio. scripts added on solution.

here bundle code:

bundles.add(new scriptbundle("~/content/themes/base/js/scripts/footeroptimized").include(     "~/themes/mytheme/content/js/bootstrap.min.js",     "~/scripts/jquery.validate.min.js",     "~/scripts/jquery.validate.unobtrusive.min.js",     "~/scripts/public.common.min.js",     "~/themes/mytheme/content/js/readmore.min.js")); 

i thought maybe use bundles .add() function error:

 bundles.add("~/themes/mytheme/content/js/global.min.js")); 

the error is: "cannot convert string system.web.optimization.bundle"

i couldn't find explaining why im getting error.

also have added using statement optimizations @using system.web.optimization;

anyone know how add bundle has been created.

update:

i have tried following doesn't work:

var footerscriptbundle = new scriptbundle("~/content/themes/base/js/scripts/footeroptimized"); footerscriptbundle.include(     "~/themes/mytheme/content/js/bootstrap.min.js",     "~/scripts/jquery.validate.min.js",     "~/scripts/jquery.validate.unobtrusive.min.js",     "~/scripts/public.common.min.js",     "~/themes/mytheme/content/js/readmore.min.js");  footerscriptbundle.include("~/themes/mytheme/content/js/global.min.js"); 

cheers

the use case you've described not appropriate bundles. cannot modify bundle @ run-time, , if could, doesn't make sense so.

think it. visit 1 page, , request , receive bundle abc.js, browser caches. then, visit different page asks abc.js, want contents different. except, browser not ask file , reuse old 1 because has been cached. bundles avoiding sending files needed across many pages.

if need bundle additional files, need either put different files own bundles , request 2 bundles on each page, or create 1 bundle each different scenario, bundle contains base files plus site-area-specific files.

however, if there 1 additional file needed , file you're trying add bundle used on single page, you're doing wrong. file doesn't belong in bundle @ all! serve usual, normal <script> or <link> tag. if have multiple files, if they're used on 1 page, perhaps combine them single (unbundled) file. or suggested above, make special bundle few files, , include or don't include second, separate bundle.

the overhead of browser having request 2 objects, bundle , page-specific javascript or second bundle, not big. won't value out of trying build bundles way, , doing headache of nightmare proportions. don't that.

some day http 2.0, might able forget bundling, since may possible browser can ask many files single request, , receive answers in single response. @ point, minification still important, abandon bundles since benefit realized through protocol itself. there still may multiple requests, split along lines of request can serviced from, example 1 request static content (images, videos, stylesheets, javascript, etc) can served cdn, , 1 request dynamic content.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -