Dropinrequire.js
dropin replacement for require() in browser
Install / Use
/learn @jeromeetienne/Dropinrequire.jsREADME
Drop-In require
dropinrequire.js is a drop-in replacement for commonjs module in a browser. No server to run, No preprocessing of javascript files. It is very simple it needs only 20-lines of js.
It is designed for rapid prototyping, not for production (see <a href="#performance">details</a>). If you are in a rush, are using node.js and are willing to share code with your browser without hassle, dropinrequire.js is for you.
How to use it
You just include this in your webpage
<script type="text/javascript" src="./dropin_require.js"></script>
And after that you can use require(filename) to import your node module in the
web browser.
Suppose you got a module foobar.js
exports.foo = "bar";
then this html will display bar. Here it is a demo to show, and not tell.
<script src="../dropin_require.js"></script>
<script>
alert( require('./foobar.js').foo );
</script>
Performance vs Compatibility
<a name="performance"></a>
dropinrequire.js goals were to be short and compatible. The compatibility part is the painfull one. Nodejs require is synchronous, so when you require you dont do anything else. To ensure compatibility, dropinrequire must be synchronous too. But It is ok for nodejs because reading files from local disks is fast, much faster than network transfert. The same doesnt apply in the browser. Because of compatibility, dropinrequire.js relies on synchronous xhr which have signficant performance issues. maybe one day i will incude a cache in LocalStorage. For now, i recommend brequire for production. It does require you to preprocess your js files on the server, but it is in the same spirit than dropinrequire.js, small and clean.
About
The code is available on github under MIT license and has been written by Jerome Etienne. That's it. No fuss no muss.
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
