【问题标题】:Aggregate and compress CSS files drupal 7聚合和压缩 CSS 文件 drupal 7
【发布时间】:2011-11-11 21:20:27
【问题描述】:

检查配置框时:

聚合和压缩 CSS 文件,它说保存成功,但该选项没有保持选中状态,并且 css 文件没有压缩到一个文件中。为什么是这样。 (使用 Drupal 7)

【问题讨论】:

  • 这似乎是 Drupal 7 中的一个错误,因此您不太可能在这里得到答案。您应该使用 Drupal file a bug report。 FWIW,我无法在我的 Drupal 7.9 站点上重现此行为。
  • 它似乎实际上压缩了 css/js 文件,但这些框并没有保持选中状态。它似乎只为匿名用户压缩文件。

标签: drupal-7


【解决方案1】:

我假设你没有提到它,javascript 聚合有效?

Drupal 的 CSS 聚合 doesn't (currently) parse the CSS,它只是在合并文件之前执行一些正则表达式,因此如果遇到有效但格式异常的 CSS,或者您可能永远不会注意到的不正确的 CSS 语法,它可能会中断。

检查您创建的任何自定义 CSS 是否有任何 CSS 错误或怪癖(任何异常),以及任何可能有错误 CSS 的非主流模块或主题。

给你一个想法,一些引起问题的事情包括

检查文件编码是否一致也是值得的。特别是,在聚合提要和文件时,一个已知的奇怪结果来源是UTF8 Byte Order Markers (BOM),它可能会错误地滑入文件中。 a command here 会从目录中的所有文件中删除所有 BOM(请谨慎使用!)。

如果 JS 聚合也不起作用,几乎可以肯定是服务器或目录问题 - 检查文件目录权限,检查您是否有适当的压缩库,以及 Duncan 提到的所有内容。

如果没有任何效果,您可以尝试agrcache moduleCore Library module。它们改变了聚合使用的方法,并可能给出不同的结果,或问题的线索。并密切关注 Drupal 7 和 Drupal 8 的聚合问题——人们正在研究的问题中可能有一些线索。

【讨论】:

    【解决方案2】:

    如果您的临时文件目录配置错误,则无法写出聚合的 CSS(和 JS)文件,我相信此选项会再次自行关闭。有时会发生这种情况,因为该目录的路径配置错误。其他时候路径设置正确,但目录上存在权限问题,这意味着网络服务器无法写入该路径。无论哪种方式,它都会阻止聚合工作。

    您可以做的另一件事是检查站点日志中是否有任何可能表明问题根源的错误消息。

    【讨论】:

      【解决方案3】:

      This is the solution.

      样式表

      <?php
      function THEME_css_alter(&$css) { 
      
        // Sort CSS items, so that they appear in the correct order.
        // This is taken from drupal_get_css().
        uasort($css, 'drupal_sort_css_js');
      
        // The Print style sheets
        // I will populate this array with the print css (usually I have only one but just in case…)
        $print = array();
      
        // I will add some weight to the new $css array so every element keeps its position
        $weight = 0;
      
        foreach ($css as $name => $style) {
      
          // I leave untouched the conditional stylesheets
          // and put all the rest inside a 0 group
          if ($css[$name]['browsers']['!IE']) {
            $css[$name]['group'] = 0;
            $css[$name]['weight'] = ++$weight;
            $css[$name]['every_page'] = TRUE;
          }
      
          // I move all the print style sheets to a new array
          if ($css[$name]['media'] == 'print') {
            // remove and add to a new array
            $print[$name] = $css[$name];
            unset($css[$name]);
          }
      
        }
      
        // I merge the regular array and the print array
        $css = array_merge($css, $print);
      
      }
      ?>
      

      脚本

      <?php
      function THEME_js_alter(&$js) {
      
        // Sort JS items, so that they appear in the correct order.
        uasort($js, 'drupal_sort_css_js');
      
        $weight = 0;
      
        foreach ($js as $name => $javascript) {
          $js[$name]['group'] = -100;
          $js[$name]['weight'] = ++$weight;
          $js[$name]['every_page'] = 1;
        }
      
      }
      ?>
      

      【讨论】:

      • 使用该解决方案,我最终会为几乎每个页面创建不同的 JS/CSS 文件。
      【解决方案4】:

      很可能您在设置文件中将该选项设置为某个值。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-05-03
        • 1970-01-01
        • 1970-01-01
        • 2011-09-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多