Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVGZ gives encoding error

Tags:

svg

I'm sitting here using SVG, and I would like to gzip those files, using the SVGZ - The problem is, that I get this error when I open the SVGZ file:

This page contains the following errors:

error on line 1 at column 1: Encoding error Below is a rendering of the page up to the first error.

I've tried creating the same svg in different types of applications, and tried it in different browsers and even servers. I've worked with svgz before, where I could get it showing, but it was some time ago..

Anyone that knows how to fix this?

like image 803
LucasRolff Avatar asked Oct 23 '11 07:10

LucasRolff


2 Answers

I found making sure the 'Image Location' is set to 'enter image description hereEmbed' and NOT 'link' in the saving to SVG settings worked for me

like image 160
Rob Avatar answered Nov 13 '22 21:11

Rob


I faced the same problem and i found the solution after some digging. My solution is for IIS but during my test i found the same behavior on Apache.

Mime type for svgz is somewhat bugged, because is the same of uncompressed SVG:

image/svg+xml

So to enable SVGZ serving on IIS i had to add a rewrite rule which added the hedaer

Content-Encoding: gzip

This was working but sometimes the browser was receiving the former encoding error.

The problem was the server treated svgz as static content, and because "static compression" was enabled on the site, the client were receiving sometimes the original content, sometimes the compressed (and cached) one, without knowing the difference because server compression act enabling the gzip Content-Encoding header, the same the rewrite rule was enabling all the times.

The client is actually unable to understand when the server re-compressed the content and when not.

The possible solutions are:

  • disable static compression at all
  • disable static compression MIME Mapping for image/svg+xml mime type. This will disable compression for svg too, but if your site serve only svgz, this won't be an issue.

The second solution for IIS can be enabled editing applicationHost.config:

    <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
        <staticTypes>
            <...>
            <add mimeType="image/svg+xml" enabled="false" />
        </staticTypes>
    </httpCompression>

Hope this will help you.

PS: this is my first post on stackoverflow!

like image 1
F. Terenzi Avatar answered Nov 13 '22 21:11

F. Terenzi