简体   繁体   English

mod_pagespeed不会组合CSS和JS

[英]mod_pagespeed won't combine CSS and JS

I've installed mod_pagespeed on our server but it won't combine my CSS and JS on our website oktoberfest.it. 我在我们的服务器上安装了mod_pagespeed但它不会在我们的网站oktoberfest.it上组合我的CSS和JS。 Obviously I've activated combine_css, combine_javascript and PassThrough in filters in pagespeed.conf file. 显然我已经在pagespeed.conf文件中的过滤器中激活了combine_css,combine_javascript和PassThrough。

I've also read that mod_pagespeed can't combine CSS files that contains CSS3 directives, but in my Apache's log file, after enabling LevelLog debug of course, there aren't any error or infos about failures in combining. 我还读到mod_pagespeed不能组合包含CSS3指令的CSS文件,但是在我的Apache日志文件中,当然启用LevelLog调试后,没有任何关于组合失败的错误或信息。 Neither CSS neither JS. 既不是CSS也不是JS。

I've tried to: 我试过:

  1. Readd CoreFilters 读取的CoreFilters
  2. Reboot Apache 重启Apache
  3. Delete mod_pagespeed cache with touch /var/mod_pagespeed/cache/cache.flush 使用touch /var/mod_pagespeed/cache/cache.flush删除mod_pagespeed缓存
  4. Deactivate all filters except combine_css and combine_javascript 停用除combine_css和combine_javascript之外的所有过滤器
  5. I've check that folders indicated in .config file are CHMOD 777 我检查.config文件中指示的文件夹是CHMOD 777

I don't know what to do now. 我现在不知道该怎么办。 I'm done with ideas. 我完成了想法。 I really want this mod_pagespeed features work with our website, we have 40 requests of CSSs and JSs that come from plugins that we can not manage. 我真的希望这个mod_pagespeed功能适用于我们的网站,我们有40个CSS和JS的请求来自我们无法管理的插件。

What do you suggest me to do? 你建议我做什么?

For CSS Combine 对于CSS组合

As you are using Wordpress, you need to add a Function in function.php of Wordpress. 当你正在使用Wordpress,您需要在添加功能function.php的WordPress。

function remove_style_id($link) {
        return preg_replace("/id='.*-css'/", "", $link);
}
add_filter('style_loader_tag', 'remove_style_id');

Wordpress writes ID="" Tags into the css link which pagespeed doesn´t like. Wordpress将ID=""标签写入了pagepeed不喜欢的css链接。 So it will be ignored. 所以它会被忽略。

BUT It "could" cause Problems with a Plugin if a Javascript calls the ID, but regular no one will do it that way. 但是 ,如果Javascript调用了ID,它“可能”导致插件出现问题,但是经常没有人会这样做。 So you´ll be safe. 所以你会安全的。

There appear to be a few issues preventing mod_pagespeed from combining resources on your site. 似乎存在一些阻止mod_pagespeed组合您网站上的资源的问题。 First of all, many of your CSS files have id attributes, which will prevent the combine_css filter from functioning. 首先,许多CSS文件都有id属性,这会阻止combine_css过滤器运行。 HTML generally expects elements to have a single id attribute, and it's not clear what that should be if those CSS files are combined. HTML通常希望元素具有单个id属性,并且如果组合这些CSS文件,则不清楚应该是什么。

That doesn't explain why mod_pagespeed does not seem to be rewriting any CSS or JS resources on your page though. 这并不能解释为什么mod_pagespeed似乎不会重写页面上的任何CSS或JS资源。 mod_pagespeed is able to rewrite the HTML, for example www.oktoberfest.it/?ModPagespeedFilters=collapse_whitespace is able to remove whitespace from the page. mod_pagespeed能够重写HTML,例如www.oktoberfest.it/?ModPagespeedFilters=collapse_whitespace能够从页面中删除空格。 The issue is likely that mod_pagespeed is not able to fetch these resources internally. 问题很可能是mod_pagespeed无法在内部获取这些资源。 This can happen for a number of reasons, but look in your apache error_log for messages related to SERF. 这可能由于多种原因而发生,但请查看apache error_log以获取与SERF相关的消息。

The best fix for fetch related failures is to use the ModPagespeedLoadFromFile directive if your environment will allow it. 获取相关失败的最佳解决方法是在您的环境允许的情况下使用ModPagespeedLoadFromFile指令。 Also have a look at this FAQ entry , which explains the problem. 另请参阅此FAQ条目 ,该条目解释了该问题。 You can also try updating to beta release 1.4.26.1 or later, which includes a workaround for common loopback fetch errors. 您还可以尝试更新到测试版1.4.26.1或更高版本,其中包括针对常见环回获取错误的解决方法。

You can permit IDs for css combining as of version 1.12.34.1, have a look at the documentation . 从版本1.12.34.1开始,您可以允许用于css组合的ID,请查看文档

As wordpress adds -css to any ID, you can just add: 由于wordpress将-css添加到任何ID,您只需添加:

Apache: 阿帕奇:

ModPagespeedPermitIdsForCssCombining *-css

Nginx: Nginx的:

pagespeed PermitIdsForCssCombining *-css;

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

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