Skip to content

Commit 6df1301

Browse files
authored
Merge pull request #447 from ByteInternet/Pre-compress-critical-served-files-in-Brotli-to-be-served-out-by-nginx
Pre compress critical served files in brotli to be served out by nginx
2 parents 0b8e35a + b1751c8 commit 6df1301

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ pub
77
.ssh
88
.vscode
99
*.css.map
10+
*.br
1011
deployment-report.json
1112
build/

deploy.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
namespace Hypernode\DeployConfiguration;
66

7-
use function Deployer\after;
8-
use function Deployer\run;
9-
use function Deployer\task;
10-
use function Deployer\test;
7+
use function Deployer\{run, task, test, within, set};
118

129
$DOCKER_HOST = '172.17.0.2';
1310
$DOCKER_WEBROOT = sprintf('/data/web/apps/%s/current/pub', $DOCKER_HOST);
@@ -74,12 +71,29 @@
7471
run('cp {{release_path}}/etc/nginx/server.redirects.conf /data/web/nginx/server.redirects.conf');
7572
});
7673

74+
// This will pre-compress files using brotli compression so we can serve them directly from nginx
75+
// without needing to compress them on-the-fly.
76+
task('build:compress:brotli', function () {
77+
set('brotli_compression_level', 11);
78+
79+
run('apt update && apt install brotli -y');
80+
within('{{release_or_current_path}}/docs/_build/html', function () {
81+
run('find . -name "*.html" -type f -exec brotli -f -q {{brotli_compression_level}} {} \\;');
82+
run('find . -name "*.css" -type f -exec brotli -f -q {{brotli_compression_level}} {} \\;');
83+
run('find . -name "*.js" -type f -exec brotli -f -q {{brotli_compression_level}} {} \\;');
84+
run('find . -name "*.svg" -type f -exec brotli -f -q {{brotli_compression_level}} {} \\;');
85+
run('find . -name "*.png" -type f -exec brotli -f -q {{brotli_compression_level}} {} \\;');
86+
run('find . -name "*.jpg" -type f -exec brotli -f -q {{brotli_compression_level}} {} \\;');
87+
});
88+
});
89+
7790
$configuration = new Configuration();
7891
$configuration->addBuildTask('node:build:scss');
7992
$configuration->addBuildTask('python:venv:create');
8093
$configuration->addBuildTask('python:venv:requirements');
8194
$configuration->addBuildTask('python:build_documentation');
8295
$configuration->addBuildTask('python:generate_redirects');
96+
$configuration->addBuildTask('build:compress:brotli');
8397
$configuration->addDeployTask('deploy:disable_public');
8498
$configuration->addDeployTask('deploy:hmv_docker');
8599
$configuration->addDeployTask('deploy:docs_vhost:acceptance');

0 commit comments

Comments
 (0)