https://en.wikipedia.org/wiki/Scalable_Vector_Graphics#Compression

SVG images, being XML, contain many repeated fragments of text, so they are well suited for lossless data compression algorithms. When an SVG image has been compressed with the industry standard gzip algorithm, it is referred to as an "SVGZ" image and uses the corresponding .svgz filename extension. Conforming SVG 1.1 viewers will display compressed images.[8] An SVGZ file is typically 20 to 50 percent of the original size.[9] W3C provides SVGZ files to test for conformance.[10]

Every web browser that supports SVG supports SVGZ as it is just a standard gzip HTTP encoding.

Having this in core means that every contrib developer can have confidence that SVGZ will work.

Problem/Motivation

Drupal is not serving SVGZ files with the correct encoding.

Proposed resolution

All that is required is for these two lines to be added to .htaccess as described here: http://kaioa.com/node/45

AddType image/svg+xml svg svgz
AddEncoding gzip svgz

nginx can also be configured to serve SVGZ correctly. At my request, Pantheon have already updated their nginx configuration to support it and I have confirmed that it works.

I have also modified web.config for IIS as described here: http://forums.iis.net/t/1175276.aspx and confirmed that it works.

Remaining tasks

none

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because Drupal is not serving SVGZ correctly by default. This means contrib developers cannot have confidence that SVGZ will work.
Issue priority Normal because only one piece of functionality is affected.
Prioritized changes This is prioritized because it is a bug fix and because it needs to be backported to Drupal 7.
Disruption This issue is not disruptive at all.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Oostie’s picture

I tried to apply the patch, but it failt applying on core/modules/system/css/system.theme.css and core/modules/toolbar/css/toolbar.icons.css because of some changes in the css files.

There also have been added some new svg files that need to be converted to svgz:

  • 787878/cog.svg
  • 787878/key.svg
  • 787878/move.svg
  • bebebe/chevron-disc-left.svg
  • bebebe/chevron-disc-right.svg
  • bebebe/cog.svg
  • bebebe/key.svg
  • bebebe/move.svg
jbrown’s picture

FileSize
113.26 KB

Thanks Oostie!

Here's a reroll.

naxoc’s picture

This looks good to me. It would be great to have this in drupal.

The only thing I am not sure about is the web.config. I can't really test that in any way, so it would be great if someone with a Windows machine could test that.

jbrown’s picture

FileSize
66.8 KB

@jessebeach requested that the SVGs be left in the repository. This patch fixes that.

naxoc’s picture

Tagging to see if someone with a windows machine will take a look. Patch still looks good to me.

naxoc’s picture

Issue summary: View changes

Update pantheon info.

jbrown’s picture

FileSize
71.56 KB

There were some new SVGs in core/modules/edit/css/edit.icons.css

jbrown’s picture

Issue summary: View changes

Fix IIS weblink.

jurgenhaas’s picture

Sounds good to me, just wondering if providing two static files with the same content (svg and svgz) is the best approach or if we shouldn't include a process to generate the compressed versions on the fly. That way this would be done dynamically even if anyone added more SVG files further down the road - either in core or in contrib.

mherchel’s picture

FileSize
60.03 KB
68.71 KB
75.93 KB

That patch screws up IIS pretty bad.

I downloaded the latest d8 via git. Installed, and tested. Worked fine.

Then I applied the patch. Now, the HTML gets generated, but all assets get 500 Internal Server Errors. This includes css, js, and images.

Let me know if there's anything you want me to try, or any more info I can get you. :)

Also, this was tested under IIS 7.5 running PHP 5.4 on Windows Server 2008R2 SP1.

Screenshots below:

Drupal 8 working before patch:

After patch:

mherchel’s picture

I found the issue. The problem was that the patch was redeclaring the svg mime type (which isn't allowed).

Removing the <mimeMap fileExtension=".svg" mimeType="image/svg+xml" /> line fixes the problem.

So, the web.config should read:

    <staticContent>
      <mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />
    </staticContent>

Removing that line fixes the issue, and I successfully tested with Chrome, FF, and IE.

jbrown’s picture

FileSize
71.5 KB

Thanks so much @mherchel!!

I have updated the patch with the change you recommended.

@jurgenhaas in theory SVGZ could be generated on the fly by Assetic, but this is a separate issue.

mherchel’s picture

Confirmed that patch in #10 applies and works perfectly for IIS.

Let me know if there's anything else. :)

jbrown’s picture

an RTBC? ;-)

jbrown’s picture

#10: svgz.patch queued for re-testing.

jbrown’s picture

Issue summary: View changes

Use summary template

jbrown’s picture

Issue summary: View changes

no remaining tests

jbrown’s picture

Issue summary: View changes

IIS has been tested

jbrown’s picture

10: svgz.patch queued for re-testing.

kbell’s picture

On a related note, I have just confirmed with Support at Pantheon that SVG compression itself is not currently supported on Pantheon. It IS on the near-term roadmap for new features, but it is NOT yet in production (or even being beta tested). The SVGZ support in the OP IS present, just not any SVG compression.

I have added a request that it be added (one more person requesting can't hurt). If this feature is important to you and you're a Pantheon client (as I am), please let them know this feature is really important to you, and maybe they'll bump it up the queue?

Cheers,
Kelly Bell

jbrown’s picture

kbell: Are you talking about live compression of SVG files by the webserver? That is not what this issue is about.

jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
rpayanm’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
69.93 KB

Status: Needs review » Needs work

The last submitted patch, 18: 2092245-18.patch, failed testing.

rpayanm’s picture

Status: Needs work » Needs review
FileSize
69.93 KB

Let me try again.

Status: Needs review » Needs work

The last submitted patch, 20: 2092245-20.patch, failed testing.

jbrown’s picture

Status: Needs work » Needs review
FileSize
35.25 KB

Testing...

jbrown’s picture

Issue summary: View changes
jbrown’s picture

Wim Leers’s picture

Issue tags: +TX (Themer Experience)
  1. +++ b/.htaccess
    @@ -24,6 +24,10 @@ ErrorDocument 404 /index.php
    +# Add correct encoding for SVGZ.
    +AddType image/svg+xml svg svgz
    +AddEncoding gzip svgz
    
    +++ /dev/null
    index b072d9b..90ebf1b 100644
    --- a/web.config
    

    These are clear wins, because they ensure the web server supports commonly used file formats. They also don't affect the TX.

  2. +++ b/core/themes/bartik/color/preview.html
    @@ -1,7 +1,7 @@
    diff --git a/core/themes/bartik/logo.svg b/core/themes/bartik/logo.svg
    deleted file mode 100644
    index 7d7cf7c..0000000
    --- a/core/themes/bartik/logo.svg
    +++ /dev/null
    @@ -1 +0,0 @@
    -<svg xmlns="http://www.w3.org/2000/svg" width="57" height="66" viewBox="471.5 467 57 66" enable-background="new 471.5 467 57 66"><path opacity=".2" fill="#303030" d="M528.5
    […]
    -6.08z"/></svg>
    diff --git a/core/themes/bartik/logo.svgz b/core/themes/bartik/logo.svgz
    new file mode 100644
    index 0000000000000000000000000000000000000000..a91a1391fb26ed2d2c4d7c6011bfd8a2de719627
    GIT binary patch
    literal 1892
    zcmV-q2b=gGiwFpjn&DIe18i?+Z!U9oX8?Vd%W@>Q5k>d@3PgKd7$EU>h+1gxkDyvJ
    […]
    

    (And same for many other SVG files.)
    These aren't clear wins.

    I'm all for improving front-end performance, but it feels like this might be too intrusive for the TX.

    It's easy enough: rename a SVGZ file to "SVG.GZ", then it's extractable like any gzip file (on OS X), and you get the original SVG to work with.

    But why do we have to ship with this? Why can't it be up to the web server to do this?

    Finally: this part of the patch does not match the issue title/IS.

Please consider doing only the "support SVGZ" bit in this patch, then it can go in easily. Converting Drupal core's SVGs can be a follow-up issue.

jbrown’s picture

Status: Needs review » Needs work

Thanks Wim.

I'll re-roll with just the SVGZ support.

There is another issue to zip the SVG files on the fly, but this will cause increased CPU load: #2448387: Ensure that anything not already compressed is compressed on the fly

jbrown’s picture

Status: Needs work » Needs review
FileSize
1.48 KB
Wim Leers’s picture

Thanks!

Only thing preventing me from RTBC'ing this: a beta evaluation. Please add that to the IS, then this is RTBC!

Wim Leers’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

For #28.

jbrown’s picture

Status: Needs work » Needs review
FileSize
4.33 KB

I wrote a test. Will update summary.

jbrown’s picture

Issue summary: View changes
jbrown’s picture

Issue tags: -Needs issue summary update +Needs backport to 7.x
Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the beta evaluation!

Super nitpicky nitpick that can be fixed upon commit:

+++ b/core/modules/system/src/Tests/System/HtaccessTest.php
@@ -38,4 +38,13 @@ protected function assertNoFileAccess($path) {
+  }
 }

We put a newline after the last method.

jbrown’s picture

FileSize
4.33 KB
540 bytes

Added the blank line.

alexpott’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 84c2ccf and pushed to 8.0.x. Thanks!

  • alexpott committed 84c2ccf on 8.0.x
    Issue #2092245 by jbrown, rpayanm: SVGZ isn't served with correct...
jbrown’s picture

Version: 7.x-dev » 8.0.x-dev
Status: Patch (to be ported) » Needs review
FileSize
1006 bytes

Sorry - my bad. I left out the web.config changes from @mherchel

Wim Leers’s picture

Status: Needs review » Closed (fixed)

@jbrown: I'm afraid you'll have to file a new issue.

Wim Leers’s picture

Status: Closed (fixed) » Fixed
ChaseOnTheWeb’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Fixed » Patch (to be ported)

Does this still need porting to 7.x per #35?

xjm’s picture

Issue tags: -Needs backport to 7.x +Needs backport to D7
jbrown’s picture

vinmassaro’s picture

Status: Patch (to be ported) » Needs review
FileSize
810 bytes

Here's a patch for D7.

osopolar’s picture

Patch in #43 works for me, thanks.

  • alexpott committed 84c2ccf on 8.1.x
    Issue #2092245 by jbrown, rpayanm: SVGZ isn't served with correct...

  • alexpott committed 84c2ccf on 8.3.x
    Issue #2092245 by jbrown, rpayanm: SVGZ isn't served with correct...

  • alexpott committed 84c2ccf on 8.3.x
    Issue #2092245 by jbrown, rpayanm: SVGZ isn't served with correct...

  • alexpott committed 84c2ccf on 8.4.x
    Issue #2092245 by jbrown, rpayanm: SVGZ isn't served with correct...

  • alexpott committed 84c2ccf on 8.4.x
    Issue #2092245 by jbrown, rpayanm: SVGZ isn't served with correct...
juankvillegas’s picture

This should be included in Drupal 7 too. Patch #43 do the work.