我正试图使用谷歌PageSpeed洞察来加速我的网站-- www.edmhunters.com。
首先,下面是我的.htaccess文件的样子
# -----------------------------------------------------------------------
# Caching for 1 Year
# -----------------------------------------------------------------------
<FilesMatch "\.(ico|svg|woff|eot|ttf)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
# -----------------------------------------------------------------------
# Caching for 1 Week
# -----------------------------------------------------------------------
<FilesMatch "\.(jpg|png|gif|css|js)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# -----------------------------------------------------------------------
# Defining MIME types to ensure the web server actually knows about them
# -----------------------------------------------------------------------
<IfModule mod_mime.c>
AddType application/javascript js
AddType application/vnd.ms-fontobject eot
AddType application/x-font-ttf ttf ttc
AddType font/opentype otf
AddType application/x-font-woff woff
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
</Ifmodule>
# -----------------------------------------------------------------------
# Compressing output
# -----------------------------------------------------------------------
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE image/x-icon image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
</Ifmodule>奇怪的是,Cache-Control头只用于媒体文件,而不是静态文件。
例如:2.jpg在redbot.org上的输出如下
HTTP/1.1 200 OK
Date: Sun, 14 Sep 2014 06:01:54 GMT
Server: Apache/2.4.7 (Ubuntu)
Last-Modified: Thu, 11 Sep 2014 13:52:29 GMT
ETag: "7391-502ca7aba5a6e"
Accept-Ranges: bytes
Content-Length: 29585
Cache-Control: max-age=604800, public
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: image/jpeg而http://www.edmhunters.com/static/img/bp-logo.9bf55788f1b6.jpg的输出如下所示
HTTP/1.1 200 OK
Date: Sun, 14 Sep 2014 05:43:28 GMT
Server: Apache/2.4.7 (Ubuntu)
Last-Modified: Tue, 26 Aug 2014 05:43:32 GMT
ETag: 1409031812.62
Content-Length: 2592
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: image/jpeg另外,根据谷歌PageSpeed窥探我的主页,HTML被缩小了,而谷歌PageSpeed窥探另一个页面说我的HTML没有缩小。
为什么会有这种不同的行为?
发布于 2014-09-14 18:40:17
我使用Django服务我的静态文件,而我的媒体文件使用Apache。通过Apache服务我的静态文件解决了这个问题。
https://stackoverflow.com/questions/25830559
复制相似问题