Hacker News new | past | comments | ask | show | jobs | submit login
CommonJS require for the browser in 1k (stuk.github.io)
28 points by stu_k on Jan 28, 2015 | hide | past | favorite | 6 comments



Here's a simple implementation in 20 lines of code - I use this in production for our single page Backbone app (migrated away from Requirejs).

https://gist.github.com/paton/ab27a1be7e843d220ee3


How does it compare to browserify? Is it a drop-in replacement?


You run Browserify to bundle your modules offline, and then embed that bundle. With require1k you just embed the script and use one of the API methods to load your main module and everything is downloaded as needed. They are two different approaches.

require1k has a limited feature set (due to its size), creates a lot of http requests and is really suited for a small prototyping where you don't want to set up Browserify's build process. Browserify is what you should actually be using for production sites.


I just plop Browserify into a project's routes (eg., using browserify-middleware [1]), and have everything automatically build when the browser requests it. With this [2], you get fast incremental builds.

[1] https://github.com/ForbesLindesay/browserify-middleware

[2] https://github.com/bjoerge/rebundler


Would window.fetch help on saving precious bytes ?


If anyone has any questions, ask away!




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

Search: