New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RequireJS is too big as a loader #1159
Comments
There's one already: https://github.com/jrburke/almond |
@kryger Doesn't it seem to support dynamic loading js(both page1.js and page2.js depend on common.js for example), does it? |
too big as a loader +1 |
@lsycxyj almond.js doesn't support dynamic loading. It just provides necessary mechanisms to start your modular app without having full But do you really need dynamic loading in production? It's definitely better for browser caching to compile everything in one file (with |
@a-ignatov-parc One file in production is not suitable for every place. Let's say you have a multiple page project, of which every page have long and distinctive logics(page A has A, B, C plugins or modules, page B has E, F, G), while all of them depend on the same basic common modules(jQuery, backbones, etc.). The common module is only needed to be downloaded once and 304 after that, instead of downloading all the same codes in the combined js in each page. Isn't it more reasonable, is it? |
@lsycxyj common solution here is to create two packages for page. With global libs that will be cached for all pages and with app modules. |
@a-ignatov-parc Do you mean to export all the libs to global by combining them instead of using requirejs to manage the dependencies? I think it is just going back to "the past style". And what about having sub-page modules, which more than having page modules sometimes? |
All i want to say is until we have http 2.0 with resource multiplexing shipped to live we need to deal with browser's restriction for parallel recourse download limit for domain.
So, to optimize your modular code for production it will be better to:
While in development you still may/should use require.js and "all that modular staff". P.S. Production optimization can vary from project to project but usually they are the same |
@a-ignatov-parc Would you please give me a project structure example? I may not know your meaning clearly. |
@lsycxyj depending on what you said earlier
You should have build pipeline to create 3 packages:
P.S. Of course for SPA build should be different. |
@a-ignatov-parc How could I load |
@lsycxyj you can't load files by almond but you can do it with your browser using If you have amd modules inside
Everything will work fine and you don't need to use full If later you will need to load other package you just create Just be sure that package's require which is initing app is placed at the end after defining all modules. |
Que treta do capeta!!! It is very simple... RTFM!!! https://github.com/requirejs/example-multipage-shim And when you build, use almond... |
As to the original question, the bulk of the loader is handling configuration options and dynamic loading of modules. If something smaller is desired, it normally means either cutting configuration option support or dynamic loading. If cutting dynamic loading, then almond is a choice. If cutting configuration option support, I do not have a specific plan for that, but since others have made AMD loaders ideally someone could create one if needed. alameda is an option for modern browsers, and it is a bit smaller than requirejs. It can get even smaller if a browser supports Promises natively in the future. For any future requirejs 3.0+ work, alameda, or similar concepts to its internals, will likely be the baseline for future requirejs versions. The goal is to shrink the size over time, but it also depends on better base capabilities in browsers. Ideally, I also would want any major version release of requirejs to work well with ECMAScript 6 modules and its module loader, but that work is still incomplete, so hard to know yet how that will turn out. So closing this as there is a general desire to make it smaller, but it will take time and will be part of larger efforts, not this particular bug. However, feel free to continue discussion here. |
Hi @jrburke I have a similar problem... maybe a little different... So, I did a pretty crazy "workaround" to solve. You talked about alameda on the post above... It's a pretty awesome stuff!!! Can I use alameda without problem? Could be some thing like this: require(['//connect.facebook.net/pt_BR/all', 'myModule']).then(function(FB, UserFacebook) {
var user = new UserFacebook(FB);
//...
}).fail(function(err) {
err.forEach(function(obj, idx, arr) {
if (obj.fail === true)
console.error(obj.moduleName, obj.message);
});
});
define('myModule', function() {
'use restrict';
function UserFacebook(FB) {
FB.init({
appId: 'xxxxxxxxxxxxxxx',
status: false,
cookie: true,
xfbml: false,
version: 'v2.0'
});
}
//...
return UserFacebook;
}); |
@a-ignatov-parc As to @jrburke Thank you for your reply. Well... |
@lsycxyj almond will make global About rare used modules you should analyze how big impact they will make on package size. If modules C, D, E are lightweight (100kb total) than i would suggest you to build them in package. They will be minified and gzipped and impact on overal size will be minimal. But you will eliminate initialization latency because there will be no loading. Also you should understand that for desktop users 100kb of extra code (minified + gzipped) is not a big deal. I don't think that this will be your performance bottleneck place. P.S. If you haven't already checked this performance checklist you definitely should do this before considering about reducing codebase size. |
@a-ignatov-parc Great conclusion site, thank you very much. Do you mean what I return in I am going to apply it to a mobile app website, so it means a lot to me, both dynamic loading and loader size. |
@lsycxyj no. When you using almond.js and r.js your amd modules not changing at all. Almond only gives you lightweight require.js globals ( To work properly all dependencies and modules should be resolved before requiring main app. |
RequireJS is an amazing loader, but it is too big in many cases. Is there a plan to make a smaller version of requirejs by less features, only supports dynamic loading js, not supports plugins and low version browswers etc, like jQuery to Zepto?
The text was updated successfully, but these errors were encountered: