{"id":18798557,"url":"https://github.com/micmro/require-demo","last_synced_at":"2026-01-02T02:30:13.598Z","repository":{"id":22081216,"uuid":"25410711","full_name":"micmro/require-demo","owner":"micmro","description":"Demo of using require in a multi-page app (a global and 0-n secondary entry files) structured with requireJS and optimized via r.js.","archived":false,"fork":false,"pushed_at":"2014-10-30T15:59:30.000Z","size":276,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T18:21:01.354Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"CognizantQAHub/Cognizant-Intelligent-Test-Scripter","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/micmro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-18T21:31:41.000Z","updated_at":"2014-10-30T15:48:42.000Z","dependencies_parsed_at":"2022-08-20T20:40:42.829Z","dependency_job_id":null,"html_url":"https://github.com/micmro/require-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micmro%2Frequire-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micmro%2Frequire-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micmro%2Frequire-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micmro%2Frequire-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/micmro","download_url":"https://codeload.github.com/micmro/require-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239727055,"owners_count":19687099,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T22:12:22.834Z","updated_at":"2026-01-02T02:30:13.554Z","avatar_url":"https://github.com/micmro.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"require-demo\n============\nDemo of using require in a multi-page app (a global and 0-n secondary entry files).\n\nSetup demo server and tools\n---------------------------\n\nIf not already installer install [node.js](http://nodejs.org/) and execute the following repo in your teminal to install [Grunt](http://gruntjs.com/), the [r.js optimizer](http://requirejs.org/docs/optimization.html) and all dependencies:\n\n``` Bash\nnpm install -g grunt-cli\nnpm install -g requirejs\nnpm install\n```\n\nYou can start the demo server with `grunt dev`\n\n\nRunning the require optimizer\n----------------------\n\n``` Bash\nr.js -o build.js\n\n# or on windows (not bash) \nr.js.cmd -o build.js\n```\n\nThis will pack the dependencies as configured in build.js and outputs them to the `optim-output` directory\n\nPerformance optimization\n----------------------\n\nI've added a `onBuildWrite` step into the build configuration (`build.js`) that allows to load the optimized require module as a `\u003cscrip\u003e` tag - this allows the preload-parser to start downloading the file earlier. So instead of nesting them in `require([], nextStage)` calls you can add them after each other in at the bottom of the document.\n\n``` Javascript\n({\n\t...\n\tonBuildWrite: function (moduleName, path, contents) {\n\t\t// This is where the magic happens:\n\t\t/// append \";require([\"moduleName\"]);\" to all entry modules\n\t\t// - this has the same result as adding insertRequire[\"moduleName\"] to all modules\n\t\tfor (var i = 0, len = config.modules.length; i \u003c len; i++) {\n\t\t\tif(config.modules[i].name === moduleName){\n\t\t\t\treturn  contents + \";require([\\\"\"+moduleName+\"\\\"]);\"\n\t\t\t}\n\t\t}\n\t\treturn contents\n\t}\n\t...\n});\n```\n\nrun the optimizer, commet out the require calls and uncomment these line both in `index.html`)\n``` HTML\n\u003cscript src=\"optim-output/common.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"optim-output/app/account-page.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"optim-output/app/pip-page.js\"\u003e\u003c/script\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicmro%2Frequire-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicmro%2Frequire-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicmro%2Frequire-demo/lists"}