简体   繁体   English

捆绑和缩小-启用的脚本不起作用时

[英]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: 然后在布局页面中调用:@ Scripts.Render(“〜/ bundles / jqueryval”)@ Scripts.Render(“〜/ bundles / session”)但是启用缩小功能后,我在chrome控制台中遇到了以下错误:

  • Uncaught SyntaxError: Unexpected identifier jqueryval:1 未捕获的SyntaxError:意外的标识符jqueryval:1
  • Uncaught SyntaxError: Unexpected identifier session:1 未捕获的SyntaxError:意外的标识符会话:1

Also i can see my scripts in tab page "Sources" of chrome developer tools - they are minificated successfully. 我也可以在chrome开发人员工具的“源”标签页中看到我的脚本-它们已成功缩小。 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). 我提供的信息不足:Application_PostRequestHandlerExecute方法中存在一些逻辑,该逻辑将一些标签直接写到响应流(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). 我注意到实际上是在缩小的js文件的末尾写了直接在响应流中捆绑在一起的标签,因此语法被破坏了,js文件不起作用(不捆绑我的方法就可以了)。 Solution: transferred my logic from Application_PostRequestHandlerExecute to Application_AuthorizeRequest method, where it should was located initially. 解决方案:将我的逻辑从Application_PostRequestHandlerExecute转移到Application_AuthorizeRequest方法,该方法最初应位于此位置。

UPDATE UPDATE
Well, tag generating logic was entirely removed from Application_PostRequestHandlerExecute method, cause only now i understand that this is absolutely wrong idea. 好吧,标记生成逻辑已从Application_PostRequestHandlerExecute方法中完全删除,仅由于现在我明白这是绝对错误的想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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