Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: compress static files #45

Merged
merged 5 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this

## [Unreleased]

### Added

- Compression of static files. During the build step, static files of type `html`, `xml`, `txt`, `css`, `js`, `svg`, `ico`, `json`, `ttf` and `otf` in `dist/app/browser/` are precompressed using gzip. Files smaller than 1300 B are not compressed. If there is a compressed version of a static file, nginx is configured to serve it instead of the uncompressed file. The necessary directives for compressing dynamically generated HTML on-the-fly have also been added to the nginx configuration ([`nginx.conf`](/nginx.conf)), however, the directives have been commented out because of the increased server CPU load associated with on-the-fly compression. Each project can choose to enable the directives as they see fit.

### Fixed

- Legacy setup code from Angular 15 to 17 migration. Angular 17 introduced several changes to the `app.module.\*`, `main.server.ts`, `main.ts`, `server.ts` and `tsconfig.\*` files. During the original v15 -> v17 update of the app all of these changes were not implemented. This fix attempts to align the app with the setup of a new modules based Angular 17 app that has SSR and i18n enabled.
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ RUN npm install
RUN npm run generate-sitemap
# Build the Angular SSR app.
RUN npm run build:ssr
# Create precompressed versions of static files (dist/app/browser/).
RUN npm run compress


# 3. Create final image, starting from base image.
Expand Down
17 changes: 17 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ upstream nodejs {
server {
listen 80;

# Enable sending precompressed ".gz" versions of static files if such exist.
# The precompressed files are created when the app is built.
# https://nginx.org/en/docs/http/ngx_http_gzip_static_module.html
gzip_static on;
# Configure compression of proxied requests.
# https://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_proxied
gzip_proxied no-cache no-store private expired auth;

# Uncomment the gzip directives below to enable on-the-fly gzip compression
# of html dynamically generated by server-side rendering. Enabling will
# increase server load, but significantly reduce the size of transfered html
# files, even on the lowest compression level (1).
# https://nginx.org/en/docs/http/ngx_http_gzip_module.html
#gzip on;
#gzip_comp_level 1;
#gzip_types text/html;

root /static;

location / {
Expand Down
Loading
Loading