whoami

Lucas Jenß

cat /etc/motd

The Coding Journal ツ — Notes taken on an epic coding journey. Technical solutions, debugging notes, and practical guides from the trenches of software development.

Close-up of white dominoes with black dots standing on green felt surface, shallow depth of field, focused mood

ls -la ~/languages/

total 8
drwxr-xr-x
▶ PHP
▶ Ruby
▶ Scala
▶ C#
▶ JavaScript
▶ Objective-C
▶ Shell Scripting

ls -la ~/toolchain/

total 7
drwxr-xr-x
▶ Typo3
▶ Akka
▶ Capistrano
▶ Git
▶ MAMP
▶ Adobe Illustrator
▶ NSTrackingArea (Cocoa)

uname -a

platforms
drwxr-xr-x
▶ Mac OS X
▶ Unix

Automating SVG compression with SVGO in a Gulp build pipeline

Design tools such as Adobe Illustrator often produce SVGs with editor metadata, unused attributes and verbose path data. Those harmless extras can inflate every icon delivered to browsers. SVGO removes much of that waste, while Gulp provides a repeatable place to run the optimisation before assets reach production.

Used well, the pipeline keeps source files editable, applies the same rules locally and in CI, and makes compressed output easy to inspect. The important work lies in configuration: removing a viewBox or rewriting an ID can save a few bytes and still break scaling, CSS references or accessible names.

Prepare a predictable SVG workflow

Start with local development dependencies and a lock file. A typical install is npm install --save-dev gulp gulp-cli svgo gulp-svgo; expose the Gulp task through an npm script so developers and CI invoke the same command. Pin dependency versions through package-lock.json and confirm that gulp-svgo supports the installed SVGO major release.

Keep authored and generated files apart. For example, place editable exports in src/icons/ and publish processed files to dist/icons/. The dist/ directory should be generated during a release, not treated as the canonical design source. This avoids a compressed file being opened, saved and optimised again.

For Sydney and Melbourne product teams, predictable asset output also reduces handoff friction between local designers, offshore studios and cloud infrastructure providers. Budgets are commonly set in Australian dollars, so avoiding needless CDN transfer and developer time is more useful than chasing the smallest possible file.

Configure SVGO without breaking assets

SVGO’s default preset covers many safe cleanups, but it is not a licence to delete structural information. A common Gulp project starts with a dedicated configuration file:

module.exports = {
  multipass: true,
  plugins: [
    {
      name: "preset-default",
      params: {
        overrides: {
          removeViewBox: false,
          cleanupIds: false
        }
      }
    },
    { name: "removeDimensions", active: false },
    { name: "removeTitle", active: false }
  ]
};

Keeping viewBox is essential for responsive scaling. Retaining dimensions and titles also protects layouts and accessible labels that depend on them. Disabling cleanupIds is conservative: it may leave a few extra characters, but avoids broken CSS selectors, fragment references and aria-labelledby relationships.

Treat these settings as project policy rather than trivia. A viewBox-only logo may justify removing dimensions, and a generated sprite may work safely with cleaned IDs. Record those exceptions in the configuration and test them against representative assets from the design system.

Automate compression in Gulp

The Gulp task can stay deliberately small because SVGO owns the transformation:

const { src, dest } = require("gulp");
const svgo = require("gulp-svgo");
const svgoConfig = require("./svgo.config");

function icons() {
  return src("src/icons/**/*.svg")
    .pipe(svgo(svgoConfig))
    .pipe(dest("dist/icons"));
}

exports.icons = icons;

The glob keeps the task focused on SVG files and leaves raster images, fonts and stylesheets to their own streams. Add icons to the project’s build series before deployment, then export a watch function that reruns it when src/icons/ changes. Gulp’s last-run signal prevents duplicate work during a single file change.

Fail the build when SVGO reports a malformed file or an invalid configuration. Silent fallback copies would let broken artwork reach the site. Use gulp --tasks to verify the public task names, and give the watcher the same configuration object as the release build rather than maintaining a second preset.

Separate authored files from generated output

Do not optimise files in place. Illustrator exports need to remain recoverable, and SVGO can make a path difficult to edit after conversion. Keep the source directory read-only from the build’s perspective, add generated directories to .gitignore, and let CI rebuild them from the committed sources and configuration.

Compression changes bytes, so caching needs an explicit policy. If deployment filenames stay stable, browsers may retain an old SVG after a release. Add a content hash to filenames or use cache rules that revalidate assets. HTTP compression such as Brotli or gzip remains separate from SVGO and should be enabled at the web server or CDN.

This matters for Australian online retailers, where a .com.au campaign can reach shoppers on mobile devices outside metropolitan NBN areas. Smaller SVGs help, but regional fixed-wireless and satellite connections still favour lean assets, sensible caching and restrained third-party scripts across the checkout journey.

Validate rendering and accessibility

Visual comparison is the strongest guard against over-optimisation. Keep a fixture set containing strokes, gradients, masks, text, transforms and unusual Illustrator exports. Render source and optimised versions at several sizes, then compare screenshots and inspect the browser console. A difference in one icon should fail the release rather than rely on a designer’s memory.

Accessibility checks belong in the same suite. Confirm that titles, role, aria-label, aria-labelledby, focus behaviour and visible text survive optimisation. Test dark and light backgrounds because colour conversion can alter edge pixels. For Australian government and council projects, WCAG conformance and the Digital Service Standard make these checks contractual rather than optional.

For related troubleshooting patterns, the project author notes are worth keeping alongside the project documentation. Store test commands and known fragile SVGs in the repository, then run the same browser matrix in CI that designers use for release sign-off.

Compare approaches and observe deployment behaviour

A one-off command is useful for an archive cleanup, but it is weak as a team process. The main alternatives have different operational strengths:

Workflow Feedback Repeatability Best fit
Manual SVGO command Fast for one file or archive cleanup Depends on the exact command Occasional maintenance
Editor export preset Immediate preview in the design tool Varies by application and user settings Design exploration
Gulp task using SVGO Runs on save, in CI and during release Scripted, versioned and testable Production asset pipelines

Production logs add another feedback loop. When Apache access logs fill with repeated requests for SVG URLs, bot traffic categories can help separate crawlers from people before a spike is misread as an attack. Pair that view with CDN headers and response sizes so genuine cache misses stand out from automated traffic.

Logging and asset telemetry should follow Australian privacy expectations. The Privacy Act and Australian Cyber Security Centre guidance are relevant when request data is retained or sent to an overseas analytics service. Minimise identifiers in build logs, document retention periods and avoid placing customer or campaign details in filenames.

Make the pipeline the release default

Adopt the pipeline by making optimisation part of the normal release series rather than an optional cleanup. Developers should see compressed output in the same local build they test, while CI checks the committed configuration, visual fixtures and deployment manifest. That gives every contributor the same result without extra setup.

Roll out gradually to the icon library first, where fixtures and usage are easiest to inventory. Record the baseline byte total, document any intentional exceptions and keep the source-to-output comparison available during review. Once the task is stable, apply it to logos and illustrations that share the same structural assumptions.

Wire SVGO into your next Gulp release, commit the configuration and test fixtures, and make compressed SVG output a required, reproducible build artefact. Run the task on every deploy so smaller assets and safer asset changes become the default rather than a forgotten optimisation.


cat ~/interests.json

KeyValue
editorTerminal-first workflow
osMac OS X / Unix
vcsGit, distributed version control
deployCapistrano, cron automation
graphicsSVG, Adobe Illustrator troubleshooting
networkingIP validation, SSH, VPN

git log --oneline --reverse

2013-10-30

Solving SVG import issues in Adobe Illustrator CS6 and CC

When importing an SVG into Illustrator, the operation fails with an unknown error [CANT]. A workaround for this Adobe-side bug.

2013

Solving NDK build issues on OS X

Troubleshooting native development kit compilation problems on Mac OS X.

2013

Programmatically adding PHP generated TypoScript to the backend configuration

Integrating dynamically generated TypoScript into Typo3 backend setups using PHP.

2013

ArgumentError: Could not parse PKey: no start line

Debugging an SSH key parsing error encountered during deployment.

2011-08-04

Validating IP-Addresses in PHP

Using PHP filter functions with flags like FILTER_FLAG_IPV4 and FILTER_FLAG_IPV6, and understanding how filter_var handles reserved IP addresses.

2011-07-09

Cocoa: Using NSTrackingArea

A short tutorial on using Cocoa's NSTrackingArea to capture mouseEntered and mouseExited events.


cat ~/contact.txt

github: github.com/x3ro
stackoverflow: x3ro
coderwall: coderwall.com/x3ro
twitter: @x3rames