T
T
TitNIk2017-05-02 20:33:55
htaccess
TitNIk, 2017-05-02 20:33:55

How to enable gzip (deflate) SVG compression?

Good evening. I entered the following code in .htaccess to enable gzip:

<IfModule mod_deflate.c>
  <IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
      SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
      RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
    </IfModule>
  </IfModule>

  <IfModule filter_module>
    FilterDeclare   COMPRESS
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/html
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/css
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/plain
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/x-component
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/javascript
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/json
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/xhtml+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/rss+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/atom+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/vnd.ms-fontobject
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type $image/svg
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $image/svg+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/x-font-ttf
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $font/opentype
    FilterChain     COMPRESS
    FilterProtocol  COMPRESS  DEFLATE change=yes;byteranges=no
  </IfModule>

  <IfModule !mod_filter.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
    AddOutputFilterByType DEFLATE application/atom+xml
  AddOutputFilterByType DEFLATE image/svg
    AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE application/x-font-ttf font/opentype
  </IfModule>
</IfModule>

Everything is ok, except for one thing - it does not compress svg. The necessary lines seem to be registered, but it still does not work. I googled, a lot of people have the same problem, but I did not find a solution. Can you tell me something? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Denis, 2017-09-01
@No1_48

This option helped me, PageSpeed ​​Insights stopped complaining about svg compression
# Forced compression for mangled titles.
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~ -]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
# Compress outgoing data with one of the following MIME types
# (before Apache version 2.3.7, no need to include `mod_filter `
# and you can remove the `` and ``
# lines since `AddOutputFilterByType` is still in the Apache core).
AddOutputFilterByType DEFLATE application/atom+xml \
application/javascript \
application/json \
application/rss+xml \
application/vnd.ms-fontobject \
application/x-font-ttf \
application/x-web-app-manifest+json \
application/xhtml+xml \
application/ xml\
font/opentype\
image/svg+xml\
image/x-icon\
text/css \
text/html \
text/plain \
text/x-component \
text/xml
code taken from here .

M
Mark, 2017-05-03
@Mark54

svg are images, compress manually.
https://habrahabr.ru/post/170509/

V
Viktor Taran, 2017-05-03
@shambler81

at one time the problem was similar, I solved it corny just put svg directly into html
. Moreover, as the measurements showed, performance even benefited from this.

V
viarda, 2020-10-02
@viarda

The topic is old, but in the TOP of Yandex.
Maybe someone will help.
We do everything on VDS like this: https://viarda.ru/still/info/nastroyka-servera/isp...
In .htaccess we write like this:

AddType     image/svg+xml              svg svgz
AddEncoding gzip                       svgz

<IfModule mod_deflate.c>
  # Включаем deflate для не стандартных заголовков:
  # http://developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
  <IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
      SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
      RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
    </IfModule>
  </IfModule>
  <IfModule mod_filter.c>
    AddOutputFilterByType DEFLATE text/plain text/css \
    								application/json text/javascript application/javascript application/x-javascript text/x-js text/ecmascript application/ecmascript text/vbscript text/fluffscript \
    								text/xml application/xml text/x-component \
    								application/xhtml+xml application/rss+xml application/atom+xml \
    								image/x-icon image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
  </IfModule>
</IfModule>

Those. first, on the server, we allow compression in gzip, and then we manage it through .htaccess.
Bottom line: download speed is higher, all gzip (deflate) tests pass

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question