Posted by & filed under JavaScript.

リンク: Nikhil Kothari’s Projects : JavaScript Utilities Project.

JavaScript Utilities Project A set of javascript-related utilities and components for Web developers doing client-side development…

The JavaScript Utilities project is oriented at developing a set of tools and components geared toward enhancing the development model around JavaScript as used for implementing rich Web applications. For example, if you are developing script-based code, you probably have desired the ability to add debug code, to increase the robustness of your code, but do not want to take the performance hit of doing so. Or you may be writing lots of script, and want to break it out into multiple files, but do not want to take the hit of multiple downloads. You might even want to generate different script for each browser, without sending down the code for all browsers to any one browser? Any of these problems sound familiar? If so, this project aims to provide some solutions. Read on…

The project introduces the notion of .jsx (extended JavaScript) and .jsa (JavaScript assembly) files. JSX files provide the ability to include conditional code via familiar preprocessor directives such as #if, #else, #endif and so on. I have also introduced a special single-line syntax to avoid requiring a terminating #endif for convenience: ## DEBUG. The tool processes these directives in order to produce a standard .js file. JSA files build on top of .jsx files. While they can include normal JavaScript and preprocessor directives, they are primarily there for including individual .jsx and .js files via #include directives. This allows you to split your script into more manageable individual chunks.

In addition to processing preprocessor directives, the tools also allow minimizing the script by stripping out whitespace, and comments. If you want to preserve some comments, which are significant, such as copyright headers, you can use the //! comment syntax introduced by this tool which results in a regular // style comment being emitted.

The full set of preprocessor directives, and the options, tools etc. are described in the readme. The downloadable binary consists of the tools, a sample Web project, a sample msbuild project, and an msbuild targets file to get you started.

The functionality can be used in three modes:

   1. A set of standalone tools that output standard .js files that you can then deploy to your web site. Command line parameters are used to control the behavior of the tools.
   2. A couple of IHttpHandler implementations that allow you to dynamically convert your code into standard .js files. This is the mode where you can benefit from implementing per-browser code in a conditional manner. AppSetting values in configuration are used to control the conversion behavior.
   3. As a script project in VS using an msbuild project along with an msbuild task that comes along with the project. MSBuild project properties are used to control the conversion behavior.

So you have some options to pick the approach most suitable for your needs.

Give this a try. There are some perf related enhancements I plan for the next release, but in the meantime, if you have suggestions for useful features, or bug fixes, or just want to share your experience in general, then by all means, the comment form below is your channel to pass along that information.

Comments are closed.