Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Browser-require.js brings "require" to the browser (just like node) (github.com/marcuswestin)
17 points by marcuswestin on Jan 31, 2011 | hide | past | favorite | 16 comments


It uses synchronous XHR to load the JS-File. Then evals the JS-String.

This is great, but I could not figure out debugging my loaded code with this solution.

Any ideas ?


Firebug and the WebKit Inspector allow you to set breakpoints by just putting "debugger;" where you want to jump into debugging.


Thanks. I did not know that.

The problem of getting stacktraces for errors remains.

UPDATE: Just tested in Safari. I get nice stacktraces there. Its only a problem in Chrome.


The main difference between this and other solutions like RequireJS is the fact that you don't have to wrap your CommonJS modules in callbacks and thus could in theory use them "unmodified".


That's one of the big differences - I'd say the other big difference is that it comes with a compiler that bundles all your required modules into a single javascript file for production


RequireJS also has it's own compiler.


Did not know that! :P

I guess browser-require will still be useful, since you can import the same files in node and in the browser


I don't understand. Require.js already works in the browser. http://requirejs.org/


require.js does asynchronous file loading and is supposed to be deployed as-is in production. Browser-require makes it easy to develop your code using synchronous require statements and straight-forward dependency management. For production it has a compiler that combines all the required files into a single file (which is the only way you should serve your javascript in production)


RequireJS also has a "compiler" that will combine your files into one or more layers for production use, as well as straightforward dependency management.


> When a module is required, we fetch it's javascript as a string using a synchronous XHR.


Obviously, that's meant for development only and that's why it also ships with it's own compiler for production (where I seriously hope they don't use a synchronous XHR to fetch the compiled code).


no, it does not :)


Right. What need does this project meet?

Sounds like a great way to create a lousy user experience.


The synchronous XHR requests are only used in your development environment. For production, use `node browser-require/compile.js`, which will compile all your required javascript modules into a single file. It really doesn't make sense to asynchronously request all of your javascript files on production pages.


Actually it makes a ton of sense to asynchronously require javascript files on your production page. If you load them asynchronously and in parallel, you can often get much better performance than one single request (serially).

http://blog.getify.com/2009/11/labjs-why-not-just-concat/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: