Skip to content

Use deep Locutus imports for browser bundle size#946

Merged
RobLoach merged 1 commit intotwigjs:masterfrom
kvz:fix/locutus-deep-imports
Mar 16, 2026
Merged

Use deep Locutus imports for browser bundle size#946
RobLoach merged 1 commit intotwigjs:masterfrom
kvz:fix/locutus-deep-imports

Conversation

@kvz
Copy link
Copy Markdown
Contributor

@kvz kvz commented Mar 14, 2026

It was reported to me that

The bundled twig.min.js file from this project is 300KB, half of which is from locutus.

Decided to lend a hand.

Summary

  • replace Locutus category-index imports in src/twig.lib.js with per-function deep imports
  • keep the runtime surface identical while letting webpack include only the 9 helpers Twig actually uses

Why

Twig currently imports Locutus like this:

  • locutus/php/strings/index
  • locutus/php/math/index
  • locutus/php/datetime/index
  • locutus/php/var/index

That pulls much more of Locutus into the browser bundle than Twig actually needs.

With this change, the locally built artifacts changed from:

  • twig.min.js: 241560 bytes -> 111095 bytes
  • twig.js: 723397 bytes -> 291023 bytes

Related

Locutus-side follow-up: locutusjs/locutus#576

@RobLoach
Copy link
Copy Markdown
Collaborator

This is a great idea, thanks

@RobLoach RobLoach merged commit 49bcb6b into twigjs:master Mar 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants