2

Gzipping static files does not work as required (as I think). I used gzippo and express.compress(). Both gzipp the files one time. There is no Content-Encoding:gzip if I refresh the page again.

Her is how I setup my express app:

    var gzippo = require('gzippo');
    var express = require('express');
    var app = express();
    app.use(express.compress());
    app.use(app.router);

    app.use(gzippo.staticGzip(__dirname + '/www'));

This is what Chrome network Response Headers show after page update:

EDITED for full request headers

    GET / HTTP/1.1
    Host: myhost.com
    Connection: keep-alive
    Cache-Control: max-age=0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/ *;q=0.8
    User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36
    Accept-Encoding: gzip,deflate,sdch
    Accept-Language: en-US,en;q=0.8
    Cookie: __utma=161759779.498387976.1381482631.1394444924.1394395346.80; __utmb=161759779.3.10.1394395346; __utmc=161759779; __utmz=161759779.1394444924.79.7.utmcsr=gtmetrix.com|utmccn=(referral)|utmcmd=referral|utmcct=/reports/myhost.com/5iXAs1ej/retest
    If-None-Match: "25020-1394452200000"
    If-Modified-Since: Mon, 10 Mar 2014 11:50:00 GMT

If I refresh again it shows: Edited with full response headers.

    HTTP/1.1 304 Not Modified
    x-powered-by: Express
    accept-ranges: bytes
    etag: "25020-1394452200000"
    date: Mon, 10 Mar 2014 10:51:45 GMT
    cache-control: public, max-age=0
    last-modified: Mon, 10 Mar 2014 11:50:00 GMT

If I edit the page again I get Content-Encoding:gzip but only one time. I don't know if there is something wrong with my express setup.

NOTE: I serve my page as: res.sendfile(__dirname + '/www/index.html');

2
  • 1
    Are you seeing a 304 Not Modified status code on the refresh? If so, then that's normal cacheing and all is well. Can you should the full headers for 2 request/response cycles? (try using curl -v on the command line) Commented Mar 9, 2014 at 23:13
  • @PeterLyons I get 304 Not Modified status code on second refresh. Please check the the question, I updated with full headers. THanks Commented Mar 10, 2014 at 10:59

1 Answer 1

3

If I edit the page again I get Content-Encoding:gzip but only one time. I don't know if there is something wrong with my express setup.

All is well. The first time your server sends the file with gzip compression. The second time the normal etag cacheing mechanism comes into play, and since the file has not been modified, the server tells the browser "you already have the right version of this file" and thus there is no need for the server to send a response body at all, just headers, thus no need for any Content-Encoding header.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I added app.use(compression()) to my project and couldn't get it to work no matter what I tried. After reading this, a simple Shift+Refresh cleared the cache and the new files were gzipped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.