Using JavaScript caching in DataWindow Designer

In DataWindow Designer, you can use the Web DataWindow JavaScript Generator wizard to create JavaScript files (at design time) that contain the JavaScript client-side methods. You can start the Web DataWindow JavaScript Generator wizard by clicking the Generate File button in the JavaScript Generation property page of the DataWindow property view or from the Tool tab of the New dialog box.

You can also generate JavaScript files for the WebDataWindowControl in the Properties window in your development environment. In Visual Studio .NET, you can also choose to use JavaScript files that are embedded in the WebDataWindow.dll assembly as a resource. See “Generating JavaScript for common management tasks”.

Shared JavaScript generation properties

These JavaScript files (HTML/XHTML) are shared by all Web formats of the Web DataWindow—XML, XHTML, and HTML.

The image shows the JavaScript generation page in the properties view

Each pass of the wizard generates only one file, which allows you to combine or separate classes of functions. Once you have generated one or more JavaScript files, you can attach them to a DataWindow object using the Filename drop-down lists (for Common Class, Date Time Management, Number Format, String Format, and User Class) in the JavaScript Generation property page.

Generating and associating JavaScript files with a DataWindow object enables the JavaScript functions to be cached and then reused each time the page containing the DataWindow object displays in the browser.

Server-side and client-side performance

When you set DataWindow properties to reference included JavaScript files, the methods defined in the referenced files are not generated with the HTML in any Web DataWindow pages that are sent to the page server and client browser. Using JavaScript files also reduces the size of the HTML page rendered in the browser.

With JavaScript caching, you improve performance on the client machine as long as the client browser is configured to use cached files. With caching enabled, the browser loads the JavaScript files from the Web server into its cache, and these become available for all the Web DataWindow pages in your application. There is no client-side performance gain if the browser does not find the JavaScript files in its cache since, in this case, it reloads the files from the Web server.

Web DataWindow JavaScript Generator wizard

With the Web DataWindow JavaScript Generator wizard, you can generate only one JavaScript file at a time. The wizard gives you the option of including all Web DataWindow methods in a single file, but you can also restrict the types of methods to include in each JavaScript file it generates every time you use the wizard. The different method types correspond to the following DataWindow HTML properties:

Table 10-6: Methods generated by JavaScript Generator wizard in cached files

HTMLGen.property

Contents of cached file

CommonJSFile

Methods used by all DataWindows.

DateJSFile

Methods used by DataWindows with date and time formatting.

NumberJSFile

Methods used by DataWindows with number formatting.

StringJSFile

Methods used by DataWindows with string formatting.

UserJSFile

User-defined client-side JavaScript methods—these cannot be generated by the Web DataWindow JavaScript Generator wizard. (See “User-defined JavaScript methods”.)

All of these properties are optional. You can set each of the properties from the JavaScript Generation page of the DataWindow property view, selecting the files you generate with the wizard as values. The wizard registers each file it generates, making it available for selection from the drop-down lists in the DataWindow property view.

When you update to a new version of DataWindow .NET, you must always regenerate the JavaScript files to ensure that any changes or enhancements in the new version are incorporated in the files.

Using the ResourceBase property

You must deploy all cached files for your Web application to your Web server. You can use relative URLs or path names for cached JavaScript files if you specify their location in the HTMLGen.ResourceBase property.

You set these on the JavaScript Generation page of the DataWindow property view in DataWindow Designer. The ResourceBase property is also used to specify the location of image files.

If you do not set the HTMLGen.ResourceBase property, you must include the complete URL in the values of any of the HTMLGen properties that you set. In either case, the URLs are rendered as SRC attributes inside SCRIPT tags in the pages generated by the Web DataWindow component and sent to the client browser.

User-defined JavaScript methods

You can also reference a file where you store your own client-side JavaScript methods. To use this feature, you must assign the name of the file to the DataWindow HTMLGen.UserJSFile property and make sure the file is available to your Web server. As for the wizard-generated JavaScript files, you can use the HTMLGen.ResourceBase property to set the location for the file, or you can include the complete path to the file in the property value assignment.

You can make this assignment in DataWindow Designer or in code. The following code sets the user-defined JavaScript file to MyMethods.JS:

wdwEmp.Modify  _
    ("DataWindow.HTMLGen.UserJSFile=" +  _
     "'http://my_server.com/JavaScripts/MyMethods.JS'")    

This example will be rendered in the generated HTML page as:

<SCRIPT LANGUAGE="JavaScript" SRC=
"http://my_server.com/JavaScripts/MyMethods.JS">
</SCRIPT>

You can then call client-side methods stored in the MyMethods.JS file from the HTML syntax rendered for (or appended to) controls in a DataWindow object. For information on generating or appending HTML syntax to controls, see “Rendering HTML for controls in an HTML Web DataWindow”.