MaxCDN / osscdn

Free CDN by MaxCDN

Home Page:http://www.osscdn.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enable gzip compression for data/json

XhmikosR opened this issue · comments

It should get compressed already. See serve.js.

I wouldn't mention it if I saw it was :P
So here, it's not compressed. Tested with grunt build && node serve.js, data/*.json isn't compressed. The rest of the files are compressed so I assume we need to specify the data/*.json manually.

This must be because data/*.json is loaded with JS so express doesn't compress those.

Very valid point. That could be it, yes. Maybe there is some alternative middleware we can use? Or perhaps the current one needs to be tweaked somehow.

I'm not sure how to do this. I think we should do it in the express side somehow.

Here's the doc. I'm guessing we would need to implement a customized filter and pass it to the middleware a parameter. I'll have a look to see what sort of request we do now.

Apparently the default filter statement matches. You can verify this easily by replacing the current compress with the following:

        app.use(express.compress({
            filter: function(req, res) {
                var match = /json|text|javascript|dart|image\/svg\+xml|application\/x-font-ttf|application\/vnd\.ms-opentype|application\/vnd\.ms-fontobject/.test(res.getHeader('Content-Type'));

                console.log(res.getHeader('Content-Type'), match);

                return true;
            }
        }));

After that run server and surf there incognito. You should see application/json true at terminal. After the initial query it returns undefined (cached I think).

Hmm indeed, now that I check again I see they are being compressed.

Sorry for the noise.

No probs. :)