简体   繁体   中英

Bundling and minification - when enabled scripts don't work

Trying to apply bundling to scripts, which worked fine when were located at pages in old way (manually). This is bundles registration:

Bundle sbundle = new ScriptBundle("~/bundles/jqueryval").Include(
            "~/Scripts/jquery-{version}.js",
            "~/Scripts/menu-correction.js",
            "~/Scripts/validation-rules.js",
            "~/Scripts/jquery.unobtrusive*",
            "~/Scripts/jquery-ui-{version}.js",
            "~/Scripts/jquery.validate*");
        bundles.Add(sbundle);

        bundles.Add(new ScriptBundle("~/bundles/session").Include(
            "~/Scripts/jquery.plugin.js",
            "~/Scripts/jquery.countdown.js",
            "~/Scripts/session-management.js"));
             //others

Then in Layout page call: @Scripts.Render("~/bundles/jqueryval") @Scripts.Render("~/bundles/session") But when minification is become enabled, i got this errors in chrome console:

  • Uncaught SyntaxError: Unexpected identifier jqueryval:1
  • Uncaught SyntaxError: Unexpected identifier session:1

Also i can see my scripts in tab page "Sources" of chrome developer tools - they are minificated successfully. Spent enough time trying to fix this. What can be a reason of this mistake? Thanks in advance.

I provided insufficient information: there is some logic in Application_PostRequestHandlerExecute method which wrotes some tags directly to response stream (is needed for js). I noticed that tags which were written directly in response stream with bundling is being written actually in the end of minificated js file.Thus, syntax is broken and js file doesn't work (Without bundling my approach works fine). Solution: transferred my logic from Application_PostRequestHandlerExecute to Application_AuthorizeRequest method, where it should was located initially.

UPDATE
Well, tag generating logic was entirely removed from Application_PostRequestHandlerExecute method, cause only now i understand that this is absolutely wrong idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM