2016-08-29 1 views
3

Wenn ich meine Website mit Google PageSpeed ​​Insight analysiere, sollte ich einige Probleme bezüglich der Komprimierung von SVG-Dateien beheben.Komprimierung und Zwischenspeicherung von SVG-Dateien in der .htaccess-Datei aktivieren

Ich habe überall im Internet gesucht, um eine Lösung für dieses Problem zu finden, aber egal, was ich tue, es scheint nicht zu funktionieren, deshalb frage ich euch jetzt.

Ich habe überprüft, ob gzip über mehrere Tools im Web aktiviert ist, und das scheint zu stimmen.

Bisher habe ich das in meiner .htaccess-Datei.

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> 

ich für jemanden wirklich hoffen, mit einer Lösung für mein Problem zu kommen, da ich mich für mehrere Stunden versucht haben.

Browser-Caching funktioniert auch nicht für SVG. Vielleicht gibt es ein ähnliches Problem?

Antwort

5

Sehr späte Antwort, aber war heute selbst das gleiche suchen.

Der korrekte Ablauf von Kopfzeile würde:

ExpiresByType image/svg+xml "access 1 month" 

Ebenso das Bild/svg + xml für die gzip Erklärungen verwendet werden.

4

Bitte diese drei in .htaccess verwenden:

AddType image/svg+xml .svg 
AddOutputFilterByType DEFLATE image/svg+xml 

################ Expires Control ################ 
ExpiresByType image/svg+xml "access 1 month" 

wird auf jeden Fall die Komprimierung aktivieren für SVG-Dateien auf der Webseite.

+0

Ich musste auch 'ExpiresActive on' vor dem' ExpiresByType ... 'hinzufügen, damit der Cache-Ablauf funktioniert. Weitere Informationen: https://htaccessbook.com/useful-htaccess-rules/ – Sphinxxx

Verwandte Themen