Notifications
Clear all

Is there a preference between JS code '#key#' vs Labels.get('key')

2 Posts
2 Users
0 Reactions
995 Views
0
Topic starter

Both '#key#' and Labels.get('key') retrieve Localized messages.

Is there a architectural preference between these approaches?

JoshuaReynolds Topic starter 2017-01-25 14:01:00

key# appears stored server-side

Labels.get('key') is client-side executed

1 Answer
0

Instances of '#key#' within a JS file are resolved on the server-side for a language (en_US, for example) when the file is first requested from a client. Subsequent requests are fast because the internationalized version of the file is already generated. Note that this only happens for JS files under the web/public/jsmodules/ folder.

I would recommend using '#key#' whenever possible because it will be faster to execute on the client. You should use Labels.get('key') when:

  • You have to construct the key at runtime
  • The message label includes arguments (ex: message.key=Failed with error: {0})
  • You are working in a JS file that is included within build.jsb; in other words, it does not live under web/public/jsmodules/