我正在努力优化我在Apache Web服务器上托管的网站,在处理我的css文件(将它们组合在一个文件中...)和img alt之后,优化图像大小并为浏览器启用gzip,...我总是YSlow得分低于58%,PageSpeed等于80%,请帮助!
这是我的.htaccess文件,我把我在gtmetrix.com上找到的一些配置作为解决方案
<IfModule mod_rewrite.c>
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
# RewriteCond %{HTTP_HOST}!^www\.exemple\.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
# RewriteRule .* - [S=1]
RewriteRule .* index.php [L]
# RewriteRule (.*)http://www.exemple.com/$1 [R=301,L]
</IfModule>
#******************Non www redirect – Canonical Issue******************
#************"Compressing files / caching"
# compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(bmp|css|flv|gif|ico|jpg|jpeg|js|pdf|png|svg|swf|tif|tiff|woff|eot|ttif)(\.gz)?$">
Header set Expires "Thu, 22 Mar 2018 20:00:00 GMT"
Header unset Etag
FileETag None
Header set cache-control "max-age=2592000, public"
</FilesMatch>
</IfModule>
答案 0 :(得分:1)
我看到你从Gtmetrix获得的截图,我认为你的一切都没问题,那些文件是外部的,所以你无法优化它们:)!检查其他建议,并尝试修复它们以获得良好的YSlow分数,最好的问候兄弟:)