我一直致力于优化某个网站,以使其在Google PageSpeed Insights工具(针对移动设备和台式机)上获得100分。大多数项目都可以正常工作,但是我仍然收到该网站的“启用压缩”警告。
这很麻烦,因为在我的服务器上启用了gzip,并且唯一未压缩的资源来自NGINX PageSpeed模块。我已经浏览了Google网站上的配置页面,但是除了已经存在的常规NGINX配置之外,没有任何内容描述如何启用压缩。
我的问题是:如何启用gzip压缩使其适用于pagespeed资源?
我的服务器设置:
Ubuntu 12.0.4.3 LTS NGINX-使用PageSpeed模块1.6.29.5 beta进行自定义编译1.5.4
NGINX服务器配置:
user www-data;
#set worker processes to cpu processes
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
client_max_body_size 200m;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
keepalive_timeout 3;
types_hash_max_size 2048;
gzip on;
gzip_disable msie6;
gzip_static on;
gzip_types text/plain text/css application/x-javascript text/xml application/xml+rss text/javascript;
gzip_vary on;
fastcgi_read_timeout 2m;
include global/caching.conf;
include /etc/nginx/enabled-sites/*;
upstream php {
server 127.0.0.1:9000;
}
#fastcgi caching header
add_header mcapp-fastcgi-cache $upstream_cache_status;
}
网站配置:
server {
server_name www.examplesite.com;
rewrite ^ $scheme://examplesite.com$request_uri permanent;
}
server {
#pagespeed directives
pagespeed On;
pagespeed FileCachePath /var/cache/nginx-pagespeed;
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/ngx_pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
#pagespeed directives end
server_name examplesite.com;
root /path/to/examplesite;
# wordpress config
include global/restrictions.conf;
include global/wordpress.conf;
}
编辑 为了进一步阐述,似乎没有压缩的特定资产是javascript资产。举个例子:
Enable compression for the following resources to reduce their transfer size by 355.5KiB (69% reduction).
Compressing http://examplesite.com/wp-includes/js/jquery/jquery.js,qver=1.10.2.pagespeed.jm.iCH2ukpEYb.js could save 58.8KiB (64% reduction).
Compressing http://examplesite.com/wp-content/themes/Avada/framework/plugins/revslider/rs-plugin/js/jquery.themepunch.revolution.min.js?ver=3.6.1 could save 43.9KiB (80% reduction).
expires 24hrs
由于某种原因我总是收到“哔哔,您拿着它不对劲”。同样适用于YSLOW