title: How can I gzip a jade template in Node JS
body: <p>I would like to gzip my index.pug because apparently it is required so that I can use certain VectorTiles on leaflet. </p>
  
  <p>Here is my server.js </p>
  
  <p>`</p>
  
  <pre><code>var loopback = require('loopback');
  var boot = require('loopback-boot');
  var compression = require('compression');
  var bodyParser = require('body-parser');
  var $ = require('jquery');
  var app = module.exports = loopback();
  var session = require('client-sessions');
  var path = require('path');
  app.set('views', path.join(__dirname, '../views'));
  app.set('view engine', 'pug');
  
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({extended: true}));
  app.use(compression());
  app.use(loopback.static(__dirname+'../views'));
  
  app.use(session({
    cookieName: 'session',
    secret: 'random_string_goes_here',
    duration: 30 * 60 * 1000,
    activeDuration: 5 * 60 * 1000,
  }));
  
  app.start = function() {
    // start the web server
    return app.listen(function() {
      app.emit('started');
      var baseUrl = app.get('url').replace(/\/$/, '');
      console.log('Web server listening at: %s', baseUrl);
      if (app.get('loopback-component-explorer')) {
        var explorerPath = app.get('loopback-component-explorer').mountPath;
        console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
      }
    });
  };
  `
  </code></pre>
  
  <p>And this is where I render my '.pug' file</p>
  
  <pre><code>`    
   module.exports = function (app) {
     app.get('/', function (req, res) {
       //res.setHeader('Content-Encoding', 'gzip');
       res.render('index.pug');
     });
   };
  `
  </code></pre>
  
  <p>I need to be able to set the header <strong>res.setHeader('Content-Encoding', 'gzip');</strong>, but when I do I get this error: ERR_CONTENT_DECODING_FAILED</p>
  
  <p>I read that the error is caused by the file not being compressed.</p>
  
  <p>This is what I get when I run curl:
  <code>
      HTTP/1.1 200 OK
      vary: Origin, Accept-Encoding
      access-control-allow-credentials: true
      x-xss-protection: 1; mode=block
      x-download-options: noopen
      x-content-type-options: nosniff
      content-type: text/html; charset=utf-8
      content-length: 26424
      etag: W/"6738-EwRjd2/5wySxOECqPhvhuiz7rTc"
      date: Wed, 10 Jan 2018 22:22:40 GMT
      X-BACKEND: apps-proxy
  </code></p>
  
  <p><strong>EDIT</strong></p>
  
  <p>So I think the problem is that compression is compressing it with zlib when I need it to be gzip. Any ideas how to change that?</p>