Question: Is it possible to use `require()` (or something similar) on client side?

**Example**

```
var myClass = require('./js/myclass.js');

```

Answer: 
If you want to have Node.js style `require` you can use something like this:

```
var require = (function () {
    var cache = {};
    function loadScript(url) {
        var xhr = new XMLHttpRequest(),
            fnBody;
        xhr.open('get', url, false);
        xhr.send();
        if (xhr.status === 200 && xhr.getResponseHeader('Content-Type') === 'application/x-javascript') {
            fnBody = 'var exports = {};\n' + xhr.responseText + '\nreturn exports;';
            cache[url] = (new Function(fnBody)).call({});
        }
    }
    function resolve(module) {
        //TODO resolve urls
        return module;
    }
    function require(module) {
        var url = resolve(module);
        if (!Object.prototype.hasOwnProperty.call(cache, url)) {
            loadScript(url);
        }
        return cache[url];
    }
    require.cache = cache;
    require.resolve = resolve;
    return require;
}());

```

Beware: this code works but is incomplete (especially url resolving) and does not implement all Node.js features (I just put this together last night).
**YOU SHOULD NOT USE THIS CODE** in real apps but it gives you a starting point. I tested it with this simple module and it works:

```
function hello() {
    console.log('Hello world!');
}

exports.hello = hello;

```
Take a look at [requirejs](http://requirejs.org/) project.