#42442·dify

[Refactor/Chore] Limit initial translation payloads to required namespaces

Author: hyobanCreated Sep 17, 2026Updated Sep 17, 2026
Labelsproject#dify

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for refactors or chores; if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Description

Load translation namespaces according to shell/route needs instead of serializing every namespace through the root layout.

web/i18n-config/server.ts:getResources loads every namespacesInFileName entry with Promise.all. web/app/components/provider/i18n-server.tsx passes that complete resource object to the client provider, mounted by the root layout.

The current registry has 38 namespaces. Compact locale JSON measurements before RSC serialization overhead:

Locale Bytes Estimated gzip bytes
en-US 408,225 105,639
zh-Hans 392,775 111,105

A DOM-backed inspection of the local datasets page found a 435,637-character inline script containing appDebug, knowledgeSpace, workflow, and billing keys together. That script also contains other data; its entire size is not attributable to translations. These resources travel in HTML/RSC data, so inspecting only package JS size misses the cost.

Motivation

Initial page data includes translations for unrelated features. Define initial shell/route namespace requirements, then load additional namespaces when needed.

Acceptance criteria:

  • Reduce initial translation resources on representative routes, including a lightweight route and datasets.
  • Update client initialization together with server selection: getInitOptions currently sets ns: namespaces, so dropping server resources alone could trigger immediate requests for all missing namespaces.
  • Preserve server/client text consistency, fallback locale behavior, language switching, and feature navigation.
  • Compare production HTML/RSC transfer and subsequent translation requests, including request waterfalls; do not merely move the same cost to dozens of immediate requests.

Additional Context

Observed on a local Dify 1.17.1 development branch based on 06e473015a9a1abb71da88ac0a0e92d96a992008, with local DevTools integration patches; Vinext 1.0.0-beta.10, Vite+ core 0.3.2, Node 24.21.0. Recheck against current main before implementation. Build measurements are diagnostic baselines, not controlled production network benchmarks.