Skip to content
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
5 changes: 4 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ jobs:
NODE_OPTIONS: --max-old-space-size=12288
executor:
name: default
resource_class: xlarge
# gen2 is ~1.4x faster CPU at +20% credits/min. Only this job runs the
# CPU-bound `yarn build`, so it's the one place the trade pays off (per
# Voltaire's gen2 rollout). Fall back to xlarge if gen2 is unavailable.
resource_class: xlarge.gen2
steps:
- checkout
- attach_workspace:
Expand Down
4 changes: 2 additions & 2 deletions bin/assert-compressed.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash

#
# A utility script to assert that all CSS, JS, JSON, and SVG files have corresponding .gz compressed versions
# A utility script to assert that all CSS, JS, and SVG files have corresponding .gz compressed versions
#
# Usage: assert-compressed.sh
#

# Find all files that should be compressed
FILES=$(find public -type f \( -name "*.css" -o -name "*.js" -o -name "*.json" -o -name "*.svg" \))
FILES=$(find public -type f \( -name "*.css" -o -name "*.js" -o -name "*.svg" \))
ORIGINAL_COUNT=$(echo "$FILES" | wc -l)

# Check each file for a corresponding .gz version
Expand Down
7 changes: 6 additions & 1 deletion data/onPostBuild/compressAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ const piscina_1 = __importDefault(require("piscina"));
*/
const onPostBuild = async ({ reporter }) => {
const cwd = path_1.default.join(process.cwd(), 'public');
const globResult = await (0, fast_glob_1.default)('**/*.{css,js,json,svg}', { cwd });
// JSON (mostly Gatsby's page-data.json) is excluded: nginx is configured with
// `gzip on; gzip_types application/json; gzip_static on;` so JSON is
// live-gzipped on the way out. Pre-compressing it with zopfli was the bulk of
// onPostBuild time for ~5-10% extra ratio over nginx's live gzip-6. Following
// Voltaire, which dropped JSON pre-compression for the same reason.
const globResult = await (0, fast_glob_1.default)('**/*.{css,js,svg}', { cwd });
const files = globResult.map((file) => {
return {
from: path_1.default.join(cwd, file),
Expand Down
7 changes: 6 additions & 1 deletion data/onPostBuild/compressAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import Piscina from 'piscina';

export const onPostBuild: GatsbyNode['onPostBuild'] = async ({ reporter }) => {
const cwd = path.join(process.cwd(), 'public');
const globResult = await fastGlob('**/*.{css,js,json,svg}', { cwd });
// JSON (mostly Gatsby's page-data.json) is excluded: nginx is configured with
// `gzip on; gzip_types application/json; gzip_static on;` so JSON is
// live-gzipped on the way out. Pre-compressing it with zopfli was the bulk of
// onPostBuild time for ~5-10% extra ratio over nginx's live gzip-6. Following
// Voltaire, which dropped JSON pre-compression for the same reason.
const globResult = await fastGlob('**/*.{css,js,svg}', { cwd });

const files = globResult.map((file) => {
return {
Expand Down
5 changes: 4 additions & 1 deletion data/onPostBuild/compressAssetsWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ const fs = require('fs/promises');
const { gzipAsync } = require('@gfx/zopfli');

const options = {
numiterations: parseInt(process.env.ASSET_COMPRESSION_ITERATIONS || '15', 10),
// Default 1: zopfli's deflate ratio plateaus after the first iteration
// (<0.5% byte savings vs. 5/15 for 25-45% more time per file). Set
// ASSET_COMPRESSION_ITERATIONS higher for production if max ratio is wanted.
numiterations: parseInt(process.env.ASSET_COMPRESSION_ITERATIONS || '1', 10),
};

const compress = async ({ from, to }) => {
Expand Down