ASP.NET:Combres 导致“$ 未定义”当 jQuery 被压缩时

发布于 2024-10-14 01:10:37 字数 3058 浏览 3 评论 0原文

对于任何具有使用 Combres 知识的人,这适合您:

我的 Combres.XML 看起来像这样:

<?xml version="1.0" encoding="utf-8" ?>
<combres xmlns='urn:combres'>

  <filters>
    <filter type="Combres.Filters.FixUrlsInCssFilter, Combres" />
  </filters >
  <cssMinifiers>
    <minifier name="yui" type="Combres.Minifiers.YuiCssMinifier, Combres">
      <param name="CssCompressionType" type="string" value="StockYuiCompressor" />
      <param name="ColumnWidth" type="int" value="-1" />
    </minifier>
  </cssMinifiers>
  <jsMinifiers>
    <minifier name="yui" type="Combres.Minifiers.YuiJSMinifier, Combres">
      <param name="IsVerboseLogging" type="bool" value="false" />
      <param name="IsObfuscateJavascript" type="bool" value="true" />
      <param name="PreserveAllSemicolons" type="bool" value="false" />
      <param name="DisableOptimizations" type="bool" value="true" />
      <param name="LineBreakPosition" type="int" value="-1" />
    </minifier>
  </jsMinifiers>
  <resourceSets url="~/combres.axd" defaultDuration="30"
                                defaultVersion="auto"
                                defaultDebugEnabled="false"
                                defaultCssMinifierRef="off" 
                                defaultJSMinifierRef="off"> 
    <resourceSet name="siteCss" type="css" minifierRef="yui">
      <resource path="~/css/jquery-ui-1.7.2.custom.css"  />
      <resource path="~/css/OMNIv2.css" />
      <resource path="~/css/dataTable.css" />
    </resourceSet>
    <resourceSet name="siteJs" type="js" >
      <resource path="~/js/jquery-1.4.2.min.js" minifierRef="off" />
      <resource path="~/js/jquery.jstree.min.js" minifierRef="off" />
      <resource path="~/js/jquery.dataTables.min.js" minifierRef="off" />
      <resource path="~/js/jquery.cookie.min.js" minifierRef="off" />
      <resource path="~/js/jquery-ui-1.7.2.custom.min.js" minifierRef="off" />
      <resource path="~/js/jquery.collapsible-v.2.1.3.js" minifierRef="yui" />
      <resource path="~/js/jquery.fileupload.js" minifierRef="yui" />
      <resource path="~/js/original/OMNIv2.js" minifierRef="yui" />
    </resourceSet>
  </resourceSets>
</combres>

将 defaultDebugEnabled 设置为 false,即该模块现在将开始运行...内联 Javascript 并且我的 ClientRegisterScriptBlocks 之一爆炸说'$ 未定义'。显然,jQuery 尚未加载或以某种方式损坏。如果我实际上在 defaultDebugEnabled 设置为 true 的情况下运行它,则组合的 JS 运行良好并且所有引用都可以工作。是否知道为什么会发生这种情况?日志显示没有任何异常。

输出:

//These are from the master page
<link rel="stylesheet" type="text/css" href="/combres.axd/siteCss/1/"/>
<script type="text/javascript" src="/combres.axd/siteJs/a/"></script>

// This is in my Default.aspx 
<script type="text/javascript" >
   function pageLoad() {
    var $NavSlider = $("#NavSlider"); // THIS DOESN'T WORK, $ is undefined
   }
</script>

For anyone who has some know-how using Combres, this is for you:

My Combres.XML looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<combres xmlns='urn:combres'>

  <filters>
    <filter type="Combres.Filters.FixUrlsInCssFilter, Combres" />
  </filters >
  <cssMinifiers>
    <minifier name="yui" type="Combres.Minifiers.YuiCssMinifier, Combres">
      <param name="CssCompressionType" type="string" value="StockYuiCompressor" />
      <param name="ColumnWidth" type="int" value="-1" />
    </minifier>
  </cssMinifiers>
  <jsMinifiers>
    <minifier name="yui" type="Combres.Minifiers.YuiJSMinifier, Combres">
      <param name="IsVerboseLogging" type="bool" value="false" />
      <param name="IsObfuscateJavascript" type="bool" value="true" />
      <param name="PreserveAllSemicolons" type="bool" value="false" />
      <param name="DisableOptimizations" type="bool" value="true" />
      <param name="LineBreakPosition" type="int" value="-1" />
    </minifier>
  </jsMinifiers>
  <resourceSets url="~/combres.axd" defaultDuration="30"
                                defaultVersion="auto"
                                defaultDebugEnabled="false"
                                defaultCssMinifierRef="off" 
                                defaultJSMinifierRef="off"> 
    <resourceSet name="siteCss" type="css" minifierRef="yui">
      <resource path="~/css/jquery-ui-1.7.2.custom.css"  />
      <resource path="~/css/OMNIv2.css" />
      <resource path="~/css/dataTable.css" />
    </resourceSet>
    <resourceSet name="siteJs" type="js" >
      <resource path="~/js/jquery-1.4.2.min.js" minifierRef="off" />
      <resource path="~/js/jquery.jstree.min.js" minifierRef="off" />
      <resource path="~/js/jquery.dataTables.min.js" minifierRef="off" />
      <resource path="~/js/jquery.cookie.min.js" minifierRef="off" />
      <resource path="~/js/jquery-ui-1.7.2.custom.min.js" minifierRef="off" />
      <resource path="~/js/jquery.collapsible-v.2.1.3.js" minifierRef="yui" />
      <resource path="~/js/jquery.fileupload.js" minifierRef="yui" />
      <resource path="~/js/original/OMNIv2.js" minifierRef="yui" />
    </resourceSet>
  </resourceSets>
</combres>

With defaultDebugEnabled set to false, i.e. the module will now start running... inline Javascript and one of my ClientRegisterScriptBlocks blows up saying that '$ is undefined'. Obviously, the jQuery hasn't been loaded or is mangled in some way. If I actually run this with defaultDebugEnabled set to true, the combined JS runs fine and all references work. Is there any idea as to why this is happening? The log shows nothing out of the ordinary.

Output:

//These are from the master page
<link rel="stylesheet" type="text/css" href="/combres.axd/siteCss/1/"/>
<script type="text/javascript" src="/combres.axd/siteJs/a/"></script>

// This is in my Default.aspx 
<script type="text/javascript" >
   function pageLoad() {
    var $NavSlider = $("#NavSlider"); // THIS DOESN'T WORK, $ is undefined
   }
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心是晴朗的。 2024-10-21 01:10:37

有趣的是,孔布雷肯定有什么问题。一些 JQuery 源文件可以工作,而另一些则不能。这取决于在某些情况下如何缩小它。在我看来,康布雷斯有一些需要解决的错误。

Interestingly enough, Combres must have some problem. Some JQuery source files would work while others wouldn't. It came down to how it was minified in some instances. Combres has some bugs to work out IMO.

万劫不复 2024-10-21 01:10:37

Combres 遇到问题是因为它试图合并并缩小已经缩小的文件。尝试使用完整的、未缩小的 JavaScript 文件。

Combres is encountering issues because it is trying to combine and minify files that are already minified. Try using the full, un-minified, javascript files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文