more generic solution with support for non-RequireJS environments