I used Meteor and Iron-router and set many server route to return some HTML with Node.js response object.
Now I want to minify and also enable gzip in response. How to do this?
This is my route code:
Router.route('/', function () {
var res = this.response;
var html = "<!DOCTYPE html>\n" +
"<html>\n" +
" <head>\n" +
" </head>\n" +
" <body>\n" +
" test\n" +
" </body>\n" +
"</html>";
res.end(html);
}, { where: 'server' });
This is page result:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
test
</body>
</html>
I want minified version like below:
<!DOCTYPE html><html><head></head><body>test</body></html>
I deploy test project in this URL:
And you can test gzip support with this tools.
Meteor already gzips and minifies (in production mode) your app.
Just not to cause the confusion your main app file the root file available at xxx.meteor.com is not impacted by this (the one containing the HTML similar to index.html).
Also this index.html LIKE file is the bare one containing the references to your js & css files. The actual js file containing your app's HTML is indeed gzipped too.
The rest of your static assets (css, js, images, etc) are all gzipd.
In production mode your css & js are also minified.
Your site at gzipminify.meteor.com has no static assets nor CSS.
On the other hand
Is the web page compressed : YES for http://test.meteor.com/5166d4fcc07e1605cbe979ef217942271d8badac.js
Is the web page compressed: NO for (http://test.meteor.com)
For a custom server side rendered route with iron router you can gzip files by including middleware with Router.onBeforeAction
instead of app.use
with the compression middleware of your choice (nodejs).