Angular2: using gzip files in production

angular, angular-cli, gzip, production-environment

Solution

You're using an obsolete version of the CLI: the newest ones don't generate the gzip files anymore.

To serve gzipped files, the browser must send a request with a header telling that it accepts gzipped responses, and the server must be configured to then gzip the files (or load the already gzipped files), and send the gzipped result, when the browser requests a file.

How to do that depends on your server.

But the index.html never refers to gzipped files. It refers to JS files. The browser asks for a JS file to the server and tells the server it accepts gzipped responses, and the server sends back the gzipped JS file, if it has been configured to do so.

Problem

I'm using angular-cli to compile my app. When running `ng build --prod` the gzip bundle files are created, but the index.html is still using the full-sized files. I tried running `ng build --prod --aot` and got the same result. How do I tell angular-cli to use .gz files in production?

Original source