javascript"

From Documentation
 
(One intermediate revision by the same user not shown)
Line 26: Line 26:
 
  [Optional]
 
  [Optional]
  
It specifies the URI of the JavaScript file to load. The URI could contain <tt>~./</tt> (such as "~./foo/whatever.js") to indicate a JavaScript file should be loaded from the classpath.
+
It specifies the URI of the JavaScript file to load. The URI can accept [[ZK_Developer%27s_Reference/UI_Composing/ZUML/Include_a_Page#Classpath_Web_Resource_Path | Classpath Web Resource Path]], <code>~./</code> (such as "~./foo/whatever.js").
 +
 
 +
If this addon [[ZK_Client-side_Reference/Language_Definition/depends| depends on another addon]], ZK generates its javaScript into a output page's <code><head></code> after the JavaScript of another addon.
  
 
=merge=
 
=merge=
 
  [Optional][Default: false]
 
  [Optional][Default: false]
  
It is used with the <tt>package</tt> attribute to specify whether the package should be loaded as part of the <tt>zk</tt> package. If not specified, each package will be loaded separatedly. This speeds up the loading if we merge several packages into one.
+
It is used with the <code>package</code> attribute to specify whether the package should be loaded as part of the <code>zk</code> package. If not specified, each package will be loaded separatedly. This speeds up the loading if we merge several packages into one.
  
 
Since ZK 6, it is allowed to specify the target package in the merge attribute. For example,
 
Since ZK 6, it is allowed to specify the target package in the merge attribute. For example,
Line 39: Line 41:
 
</source>
 
</source>
  
In fact, <tt>merge="true"</tt> is the same as <tt>merge="zk"</tt>, i.e., merged to the <tt>zk</tt> package. Notice that the target package must be a preloaded package. In other words, it must be specified in another <tt>javascript</tt> element (without the <tt>ondemand</tt> attribute). In most cases, you shall use <tt>zk</tt> for packages that can be cached at the client, and use <tt>zul.lang</tt> for packages that shall  not be cached, such as your own locale-dependent messages.
+
In fact, <code>merge="true"</code> is the same as <code>merge="zk"</code>, i.e., merged to the <code>zk</code> package. Notice that the target package must be a preloaded package. In other words, it must be specified in another <code>javascript</code> element (without the <code>ondemand</code> attribute). In most cases, you shall use <code>zk</code> for packages that can be cached at the client, and use <code>zul.lang</code> for packages that shall  not be cached, such as your own locale-dependent messages.
  
 
For more information, please refer to the [[ZK Developer's Reference/Performance Tips/Minimize Number of JavaScript Files to Load|Performance Tips]] section.
 
For more information, please refer to the [[ZK Developer's Reference/Performance Tips/Minimize Number of JavaScript Files to Load|Performance Tips]] section.
Line 46: Line 48:
 
  [Optional][Default: false]
 
  [Optional][Default: false]
  
It is used to 'cancel' the package specified in another <tt>javascript</tt> element. By default, JavaScript packages are loaded on-demand (i.e., when it is required). By specify &lt;javascript;&gt; in a language definition/addon, we could force some packages to load at the beginning. But if you change your mind, you could either remove  the <tt>javascript</tt> element, or specify another <tt>javascript</tt> element with <code>ondemand="true"</code>.
+
It is used to 'cancel' the package specified in another <code>javascript</code> element. By default, JavaScript packages are loaded on-demand (i.e., when it is required). By specify &lt;javascript;&gt; in a language definition/addon, we could force some packages to load at the beginning. But if you change your mind, you could either remove  the <code>javascript</code> element, or specify another <code>javascript</code> element with <code>ondemand="true"</code>.
  
 
=Version History=
 
=Version History=
Line 55: Line 57:
 
| 6.0.0
 
| 6.0.0
 
| September 2011
 
| September 2011
| The merge attribute could be specified with the package's name to merge to, such as <tt>zul.lang</tt>.
+
| The merge attribute could be specified with the package's name to merge to, such as <code>zul.lang</code>.
 
|}
 
|}
  
 
{{ZKClient-sideReferencePageFooter}}
 
{{ZKClient-sideReferencePageFooter}}

Latest revision as of 08:10, 24 October 2022


Syntax:

<javascript package="pkg_name" [merge="false|true"]/>
<javascript package="pkg_name" merge="a_package_to_merge_to"/>
<javascript package="pkg_name" [ondemand="false|true"/>
<javascript src="a_uri"/>
<javascript>
js_code
</javascript>

It specifies the JavaScript package or file that has to be loaded to the client. It could also specify the content (the JavaScript code snippet) directly. Notice that, if specified, it is always loaded, no matter if it is required or not.

Example,

<javascript package="zul.box"/>

package

[Optional]

It specifies the package to load.

src

[Optional]

It specifies the URI of the JavaScript file to load. The URI can accept Classpath Web Resource Path, ~./ (such as "~./foo/whatever.js").

If this addon depends on another addon, ZK generates its javaScript into a output page's <head> after the JavaScript of another addon.

merge

[Optional][Default: false]

It is used with the package attribute to specify whether the package should be loaded as part of the zk package. If not specified, each package will be loaded separatedly. This speeds up the loading if we merge several packages into one.

Since ZK 6, it is allowed to specify the target package in the merge attribute. For example,

<javascript package="foo.lang" merge="zul.lang"/>

In fact, merge="true" is the same as merge="zk", i.e., merged to the zk package. Notice that the target package must be a preloaded package. In other words, it must be specified in another javascript element (without the ondemand attribute). In most cases, you shall use zk for packages that can be cached at the client, and use zul.lang for packages that shall not be cached, such as your own locale-dependent messages.

For more information, please refer to the Performance Tips section.

ondemand

[Optional][Default: false]

It is used to 'cancel' the package specified in another javascript element. By default, JavaScript packages are loaded on-demand (i.e., when it is required). By specify <javascript;> in a language definition/addon, we could force some packages to load at the beginning. But if you change your mind, you could either remove the javascript element, or specify another javascript element with ondemand="true".

Version History

Last Update : 2022/10/24


Version Date Content
6.0.0 September 2011 The merge attribute could be specified with the package's name to merge to, such as zul.lang.



Last Update : 2022/10/24

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.