diff --git a/inc/init.php b/inc/init.php
index 00d6a6a9055337444b2bf77b667386d5b2a68feb..4289e30a997590a0f646c5858eb81331e8ab9c3f 100644
--- a/inc/init.php
+++ b/inc/init.php
@@ -60,6 +60,14 @@
   // make session rewrites XHTML compliant
   @ini_set('arg_separator.output', '&');
 
+  // enable gzip compression
+  if ($conf['gzip_output'] &&
+      !defined('DOKU_DISABLE_GZIP_OUTPUT') &&
+      function_exists('ob_gzhandler') &&
+      preg_match('/gzip|deflate/', $_SERVER['HTTP_ACCEPT_ENCODING'])) {
+    ob_start('ob_gzhandler');
+  }
+
   // init session
   if (!headers_sent() && !defined('NOSESSION')){
     session_name("DokuWiki");
diff --git a/inc/template.php b/inc/template.php
index 7a7e751a9568b77b80eabcc53754450537807460..e79b312dbf8585a168315c323636f2649770bf1f 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -19,10 +19,6 @@
 function template($tpl){
   global $conf;
 
-  if ($conf['gzip_output'] && extension_loaded('zlib') && preg_match('/gzip|deflate/', $_SERVER['HTTP_ACCEPT_ENCODING'])) {
-    ob_start('ob_gzhandler');
-  }
-
   if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl))
     return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl;
 
diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php
index 7f5024b2d2f4b1d423458ec81c81706791a90ebb..f1cf9c7b4eb5fbb626b4d7b2f7aa89e7ffb86d82 100644
--- a/lib/exe/fetch.php
+++ b/lib/exe/fetch.php
@@ -7,6 +7,7 @@
  */
 
   if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
+  define('DOKU_DISABLE_GZIP_OUTPUT', 1);
   require_once(DOKU_INC.'inc/init.php');
   require_once(DOKU_INC.'inc/common.php');
   require_once(DOKU_INC.'inc/pageutils.php');