Skip to content

Use deep Locutus imports for browser bundle size#946

Open
kvz wants to merge 1 commit intotwigjs:masterfrom
kvz:fix/locutus-deep-imports
Open

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

Conversation

@kvz
Copy link

@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
Collaborator

This is a great idea, thanks

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.

2 participants