When I analyze my website with Google PageSpeed Insight, I should fix some problems regarding compression of SVG files.
I've been looking all around the web trying to find a solution on this problem, but no matter what I do it doesn't seem to work, so therefor I'm now asking you guys.
I've checked if gzip is enabled through multiple tools on the web, and that seem to be true.
So far I got this in my .htaccess file.
RewriteEngine On
Options FollowSymLinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /#/$1 [L]
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "access 1 week"
ExpiresByType text/html "access 1 day"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType image/x-icon "access 1 month"
ExpiresByType image/svg "access 1 month"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
## FILE COMPRESSION ##
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|svg|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^image/svg+xml.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
## FILE COMPRESSION ##
# mod_deflate configuration
<IfModule mod_deflate.c>
# Restrict compression to these MIME types
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xml+rss
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE image/svg
AddOutputFilterByType DEFLATE image/svg+xml
<IfModule mod_headers.c>
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>
I really hope for someone to come up with a solution to my problem since I've tried myself for several hours.
Browser caching doesn't work for SVG neither. Maybe there are a similar problem?
Very late response but was seeking the same myself today.
The correct expires by header line would be:
ExpiresByType image/svg+xml "access 1 month"
Likewise the image/svg+xml can be used for the gzip declarations.
Please use these three in .htaccess:
AddType image/svg+xml .svg
AddOutputFilterByType DEFLATE image/svg+xml
################ Expires Control ################
ExpiresByType image/svg+xml "access 1 month"
Definitely will enable compression for svg files on website.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With