Skip to content

[Issue] Initialize inline translations module only when they are enabled #29553

Closed
@m2-assistant

Description

@m2-assistant

This issue is automatically created based on existing pull request: #27696: Initialize inline translations module only when they are enabled


Description (*)

This PR is a part of my effort to improve Magento 2 frontend performance.

The focus point of this PR was to remove downloading of inline translations JavaScript modules when they are not enabled. This was happening because they were defined in deps, which is completely redundant because they are properly initialized in https://github.com/krzksz/magento2/blob/98e04e174906799b941011a9fb1b5890a5e7cae9/app/code/Magento/Translation/view/frontend/templates/translate_inline.phtml#L57

While I was touching the files anyway I took the liberty to:

  • Move escapeHTML to utilities (it is not used anywhere else and there is already an unescape counterpart).
  • Fixed utilities dependency for serialize method.
  • Simplify logic and variables in few places.

Performance improvement

Tested on Magento 2.4-develop with Luma and sample data.

  • 207 → 203 JS requests (-1.93%).
  • 794.39kB → 773.44kB JS transferred (-2.64%).

Manual testing scenarios (*)

  1. When inline translations are disabled there is no request for translate-inline JS file.
  2. When inline translations are enabled, they work as expected.

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

Metadata

Metadata

Assignees

Labels

Component: TranslationFixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: Format is not validGate 1 Failed. Automatic verification of issue format is failedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: doneReported on 2.4.0Indicates original Magento version for the Issue report.Severity: S3Affects non-critical data or functionality and does not force users to employ a workaround.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions