Nanometer Process Machine


    0.4.6 • Public • Published


    RequireOnce is mostly a browser library that is inspired by requirejs and adds additional code from other sources to the current app context.

    What is it?

    Require Once is a first and foremost a client (browser) javascipt library that is inspired by requirejs but loads modules off the network automatically and so your index page is not filled with <script src="path/to/dependency"></script>. As the name implies, it will require whatever your dependency once and if you require it again, it will just use whatever it got the first time around. This means that you can require your own dependencies from within the JS files that need them rather than from elsewhere. You can also use it in node so your browser and server can share some of the same code base if you so desire.


    Browser: <script src="path/to/require_once.min.js"></script>

    node: npm install require_once --save


    the library creates a requireOnce and require_once (alias) function in your global scope and you can call them to require your libraries from URLs. Please be advised that the URLs should be absolute paths (aka starting with "http(s)://", "//", or "/"). All paths are relative to the HTML document that the app is ran and not the path of the file the includeOnce is called in. as a result, it's the best to just use absolute paths .

    requireOnce(array url, function callback[, function failedCallback])

    General usage example:

    ], function(jquery, uiCSS, jqueryUI, hammerjs){
        new Hammer($("body")[0])
            .on("tap", function(ev){
                console.log("Eeeww I've been touched");


    MIT = free for all yay?



    Should actually finally fix the bug that was causing the resolution function to resolve twice this time hopefully for real and forever.


    Removed Debugging "console.log" from min file


    Fixed a bug that made callbacks resolve twice sometimes.


    Actually Fixed a bug that was supposed to be fixed in 0.4.2


    Fixed a bug that made the require_once choke on null requires


    Fixed a bug that caused the resolution order to be forwards instead of backwards


    This update is yet another update that would cause potentially breaking changes to the code However it is for the best as it is a before the validation script for checking if we are able to use require once is

    if (typeof requireOnce != "undefined") var requireOnce = require("require_once");

    however because of hoisting this line actually become

    var requireOnce;
    if (typeof requireOnce != "undefined") requireOnce = require("require_once");

    which means that in the case that you are loading require_once off the main script that's no big deal but if a script is being required the declaration above would override the global requireOnce function and as a result the workaround would be to declare a requireOnce AND require_once within the scope of the required script's execution scope. This is not the most ideal and would likely lead to more hacks down the line in order to make things work (eg: potential issues in Electrons dev environment if i ever get around to supporting that). In order to avoid this problem the code that checks for if requireOnce is useable or not should be modified to

    var requireOnce = (typeof require_once == "function")? require_once : require("require_once");

    this line declares a locally scoped version of requireOnce based on the globally scoped require_once or uses node's require function to get the function. This way it simplifies the need for require once being declared in the code execution scope just to have things work. If you are exclusively running require_once from within the browser then there should be no problem for you with this update.


    npm i require_once

    DownloadsWeekly Downloads






    Last publish


    • muggy8