version 1.2.0+1 (3/1/2014) Build Status

is_client is a small Dart package with properties (isClient, isDartClient) to check if your application is running on server-side or client-side. You can also check if the client-side code is running as Dart (on Dartium) or as compiled JavaScript (on Chrome/Firefox/etc).

The dead code blocks isolated by <code>isClient</code> property value can be subjected to a dead code elimination feature provided by <code>dart2js</code>, the Dart to Javascript compiler.

API Document


Code Example

// Exmple: Check if this code is running on client-side or server-side.

import "package:is_client:is_client.dart"
if ( isClient) {
  print("Hello! I'm on client-side!");
} else {
  print("Hello! I'm on server-side!");
// Example: Check if this code is run as JavaScript or not.

import "package:is_client:is_dartium.dart"
if ( isDartClient) {
  print("Hello! I'm running Dart!");
} else {
  print("Hello! I'm running JavaScript!");

Compile-time dead code elimination

By default, a value for <code>isClient</code> property is generated runtime. It is not treated as the compile-time constants. Meaning, code blocks isolated by <code>if</code> statements WILL NOT be targeted by a dead code elination feature in <code>dart2js</code>.

To compile out the dead code, you must pass a <code>IS_CLIENT</code> constant variable to <code>dart2js</code> via a <code>-D</code> command line argument.

dart2js --minify -DIS_CLIENT=true myapp.dart
import "package:is_client:is_client.dart"
if (isServer) {
  print("Hello! I'm a nonexisting code block compiled out by dart2js!");
} else {
  print("Hello!, client!");

Change Logs

1.2.0 (2/28/2014) * Tested with dart-1.2.0

1.1.3 (2/15/2014) * Tested with dart-1.1.0, dart 1.1.3


is_client.dart is released under the [the MIT license](LICENSE) by Hiroshi Yamamoto



Properties to check if an application is running on server-side or client-side.


Properties to check if a Dart application is running on server-side or client-side, Dart browsers or other JS browsers. This library can only be imported by a client-side code since this depends on <code>'dart:html'</code>