# Verhalten mit gzip bei aktiviertem HttpCache

**URL:** <https://forum.shopware.com/t/verhalten-mit-gzip-bei-aktiviertem-httpcache/51997>\
**Category:** Installation/Einstieg\
**Created:** [23. März 2018 um 19:33 UTC](https://forum.shopware.com/t/verhalten-mit-gzip-bei-aktiviertem-httpcache/51997 "2018-03-23T19:33:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arithon](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@Arithon](https://forum.shopware.com/u/Arithon)\
**Post date:** [23. März 2018 um 19:33 UTC](https://forum.shopware.com/t/verhalten-mit-gzip-bei-aktiviertem-httpcache/51997/1 "2018-03-23T19:33:18Z")

</div>

Hallo zusammen,

wie die Frage im Titel andeutet, bekomme ich den Content bei aktiviertem HttpCache nicht komplett komprimiert (gzip) ausgeliefert.  
.css (Request URL: [http://www.subdomain.domain/web/cache/xxx.css](http://www.subdomain.domain/web/cache/xxx.css)) und .js (Request URL: [http://www.subdomain.domain/web/cache/xxx.js](http://www.subdomain.domain/web/cache/xxx.js)) werden zwar nach wie vor „gezipped“  
aber die eigentlich aufgerufene Seite (Request URL: [http://www.subdomain.domain/](http://www.subdomain.domain/)) leider nicht. Stelle ich den HttpCache nun aber aus, so werden alle Teile „gezipped“.

aktivierter HttpCache

&nbsp;

nicht aktivierter HttpCache

&nbsp;

hier meine Cache Einstellungen aus dem Backend (Frontend cache (HTTP cache):  
&nbsp;

```
Admin-View: Nein

Cache-Controller / Zeiten:
frontend/listing 3600
frontend/index 3600
frontend/detail 3600
frontend/campaign 14400
widgets/listing 14400
frontend/custom 14400
frontend/sitemap 14400
frontend/blog 14400
widgets/index 3600
widgets/checkout 3600
widgets/compare 3600
widgets/emotion 14400
widgets/recommendation 14400
widgets/lastArticles 3600
widgets/campaign 3600
frontend/listing/layout 3600

NoCache-Controller / Tags:
widgets/lastArticles detail
widgets/checkout checkout,slt
widgets/compare compare

```

&nbsp;

.htaccess:

```
RewriteEngine on

RewriteBase /
# Https config for the backend
#RewriteCond %{HTTPS} !=on
#RewriteRule backend/(.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteRule shopware.dll shopware.php
RewriteRule files/documents/.* engine [NC,L]
RewriteRule backend/media/(.*) media/$1 [NC,L]

RewriteCond %{REQUEST_URI} !(\/(engine|files|templates|themes|web)\/)
RewriteCond %{REQUEST_URI} !(\/media\/(archive|banner|image|music|pdf|unknown|video)\/)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ shopware.php [PT,L,QSA]

# Fix missing authorization-header on fast_cgi installations
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

    # Restrict access to VCS directories
    RedirectMatch 404 /\\.(svn|git|hg|bzr|cvs)(/|$)

    # Restrict access to root folder files
    RedirectMatch 404 /(autoload\.php|composer\.(json|lock|phar)|README\.md|UPGRADE-(.*)\.md|CONTRIBUTING\.md|eula.*\.txt|\.gitignore|.*\.dist)$

    # Restrict access to shop configs files
    RedirectMatch 404 /(web\/cache\/(config_\d+\.json|all.less))$

    # Restrict access to theme configurations
    RedirectMatch 404 /themes/(.*)(.*\.lock|package\.json|\.gitignore|Gruntfile\.js|all\.less|node_modules\/.*)$

# Staging environment
#SetEnvIf Host "staging.test.shopware.in" SHOPWARE_ENV=staging

# Development environment
#SetEnvIf Host "dev.shopware.in" SHOPWARE_ENV=dev
#SetEnv SHOPWARE_ENV dev

DirectoryIndex index.html
DirectoryIndex index.php
DirectoryIndex shopware.php

# Disables download of configuration

    # Deny all requests from Apache 2.4+.
    
          Require all denied
    

    # Deny all requests from Apache 2.0-2.2.
    
        Deny from all
    

    
        ExpiresActive on
        ExpiresDefault "access plus 1 month"
    

    
        Header append Cache-Control "public"
        Header unset ETag
    

    FileETag None

# Match generated files like:
# 1429684458_t22_s1.css
# 1429684458_t22_s1.js

    
        Header set Cache-Control "max-age=31536000, public"
    

    
        ExpiresActive on
        ExpiresDefault "access plus 1 year"
    

# Disables auto directory index

	Options -Indexes

    Options -MultiViews

   Header append X-Frame-Options SAMEORIGIN

  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

```

und dann noch meine php.ini:

```
zend_extension =/.../htdocs/ioncube/ioncube_loader_lin_7.0.so
max_execution_time=300
memory_limit=256M
upload_max_filesize=40M
expose_php = Off
zend_extension=opcache.so;
opcache.enable=1;
opcache.memory_consumption=32;
opcache.interned_strings_buffer=8;
opcache.max_accelerated_files=6000;
opcache.revalidate_freq=180;
opcache.fast_shutdown=0;
opcache.enable_cli=0;
opcache.revalidate_path=0;
opcache.validate_timestamps=2;
opcache.max_file_size=0;
opcache.file_cache= /.../htdocs/.opcache;
opcache.file_cache_only=1;
zlib.output_compression =1
zlib.output_compression_level =-1

```

Ach… Ja, die Seite liegt auf nem 1und1 Server (Unlimited Plus 4GB) und ich habe sie auf ner Subdomain laufen (htdocs/subdomain/). Die oben erwähnte php.ini hat Symlinks in den Unterordnern von „subdomain“. Die Shopware Version ist 5.3.7 und die verwendete PHP-Version ist 7.0. Ioncube und OPCache sind, wie man ja erkennnen kann, auch eingerichtet. Das selbe Phänomen gibts aber auch mit einer frisch installierten 5.4.1 Version unter PHP 5.6, 7.0 und 7.1 .

Ich hoffe, dass ich genug Infos angegeben&nbsp; habe damit ihr vielleicht einen Fehler ausfindig machen könnt. Mit Shopware bin ich leider noch nicht so geübt, da ich mich bisher nur mit Magento beschäftigt habe, aber da ich unseren bestehenden Shop eh migrieren muss, lag es ja nahe sich auch mal dieses System anzugucken. Vielleicht habt ihr ja eine Idee wie ich unsere Shopware-Testinstallation mit aktiviertem HttpCache UND gzip ans Laufen bekomme. Vielleicht bin ich auch einfach nur komplett auf dem Holzpfad und ihr könnt mir den Weg zeigen. Vielen Dank im Voraus.

---

<div class="post-metadata">

**Author:** ![Arithon](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@Arithon](https://forum.shopware.com/u/Arithon)\
**Post date:** [23. März 2018 um 19:40 UTC](https://forum.shopware.com/t/verhalten-mit-gzip-bei-aktiviertem-httpcache/51997/2 "2018-03-23T19:40:53Z")

</div>

Im Theme-Manager sind die Häkchen bei css, js komprimieren gesetzt. Der Shop ist im Produktivmodus (naja, je nachdem wie der HTTPCache ausgewählt ist). Wenn noch Infos fehlen…Stelle sie gerne zur Verfügung, wenn ich kann. 😉

Update…

Nach einigem “Forschen” konnte ich gzip auch mit aktiviertem HTTPCache aktivieren. Ist vermutlich keine saubere Lösung und ich weiß auch noch nicht wie ich das updatesicher hinbekomme, aber im Moment funktioniert gzip-technisch alles so wie es soll. Bitte steinigt mich nicht, wenn ich poste was ich getan habe. 😉

Unter vendor/symfony/http-foundation habe ich die Response.php editiert.

public function sendHeaders()  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp; &nbsp;$this-\>headers-\>remove(‘Content-Length’); //ermöglicht gzip unter Symfony  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // headers have already been sent by the developer  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (headers\_sent()) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $this;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!$this-\>headers-\>has(‘Date’)) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>setDate(\DateTime::createFromFormat(‘U’, time()));  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // headers  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach ($this-\>headers-\>allPreserveCase() as $name =\> $values) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach ($values as $value) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; header($name.’: '.$value, false, $this-\>statusCode);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // status  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; header(sprintf(‘HTTP/%s %s %s’, $this-\>version, $this-\>statusCode, $this-\>statusText), true, $this-\>statusCode);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // cookies  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach ($this-\>headers-\>getCookies() as $cookie) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($cookie-\>isRaw()) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setrawcookie($cookie-\>getName(), $cookie-\>getValue(), $cookie-\>getExpiresTime(), $cookie-\>getPath(), $cookie-\>getDomain(), $cookie-\>isSecure(), $cookie-\>isHttpOnly());  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setcookie($cookie-\>getName(), $cookie-\>getValue(), $cookie-\>getExpiresTime(), $cookie-\>getPath(), $cookie-\>getDomain(), $cookie-\>isSecure(), $cookie-\>isHttpOnly());  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $this;  
&nbsp;&nbsp;&nbsp; }

Bei mir habe ich in Zeile 327 folgendes ergänzt - $this-\>headers-\>remove(‘Content-Length’);

Wenn einer von euch einen besseren Weg kennt um das gewünschte Verhalten mit gzip zu realisieren… Bitte, Bitte, her damit. Wenn ich Zeit habe, werde ich wohl auch versuchen das auf einem anderen Weg zu lösen, aber ich würde mich sehr über konstruktive Vorschläge freuen.

Hat sich übrigens mit dem Wechsel des Hosters erledigt. Beim Neuen brauchte ich diese Änderung nicht und konnte sie wieder rückgängig machen. Vielleicht hilft es trotzdem mal jemanden. … dann wohl auch “noch” bei 1und1 😉

---

<div class="post-metadata">

**Author:** ![Fl0](https://avatars.discourse-cdn.com/v4/letter/f/a9adbd/32.png) [@Fl0](https://forum.shopware.com/u/Fl0)\
**Post date:** [9. April 2019 um 13:45 UTC](https://forum.shopware.com/t/verhalten-mit-gzip-bei-aktiviertem-httpcache/51997/3 "2019-04-09T13:45:05Z")

</div>

Vielen Dank, die Lösung hat mir geholfen.

@Arithon‍ habt ihr inzwischen eine updatesichere Lösung?

@SebastianKlöpper‍ wäre es nicht sinnvoll diese Änderung direkt in Shopware zu übernehmen?

&nbsp;

edit: Wir sind übrigens nicht bei 1und1 sondern bei Domainfactory

---

<div class="post-metadata">

**Author:** ![malberti](https://avatars.discourse-cdn.com/v4/letter/m/5f8ce5/32.png) [@malberti](https://forum.shopware.com/u/malberti)\
**Post date:** [12. November 2020 um 08:54 UTC](https://forum.shopware.com/t/verhalten-mit-gzip-bei-aktiviertem-httpcache/51997/4 "2020-11-12T08:54:41Z")

</div>

Gibt es hierzu mittlerweile eine Antwort?? Ich habe das selbe Problem nur hilft mir leider der kleine Workaround nicht.

---

<div class="post-metadata">

**Author:** ![Arnold](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@Arnold](https://forum.shopware.com/u/Arnold)\
**Post date:** [7. Dezember 2020 um 10:14 UTC](https://forum.shopware.com/t/verhalten-mit-gzip-bei-aktiviertem-httpcache/51997/5 "2020-12-07T10:14:17Z")

</div>

Hi all. What’s the best way to enable gzip compression on my site? I found about editing .htaccess. Is this still best practice?

My web host is [name.com](http://name.com), and they don’t offer any means to enable gzip compression–they say I have to handle it myself&nbsp;[IndigoCard](https://www.indigocard.us/)

Thanks in advance.
