8

I am searching for an AMD loader that supports dynamic code loading, and that is very small.

The loader is to be used in a mobile/high latency environment, and the size of requirejs simply is too much.

I do NOT need:
-text plugins
-css plugins
-i18n plugins

What is the smallest AMD loader that supports these features? I'm looking for something that ideally is no larger than 5k when minified. Gzip is not to be included in this measure.

duck degen
  • 1,163
  • 1
  • 9
  • 16
  • Almond.js is 2.4kb minified. 1.2kb gzipped. – ddotsenko Jan 15 '13 at 20:22
  • Almond.js does NOT support dynamic code loading unfortunately. – duck degen Jan 16 '13 at 07:08
  • I am a big fan of CurlJS. I found it to be much more reliable than RequireJS. Plus, while it's not under requested 5kb, it's still fairly small - 8kb, while packing dynamic loading. https://github.com/cujojs/curl/blob/master/dist/curl/curl.js – ddotsenko Jan 16 '13 at 17:36
  • i'm working a similar problem, hoping to get a discussion going (http://stackoverflow.com/questions/14986400/what-amd-script-loader-to-use-for-mobile-site). one difference is that i do not require lazy loading. i am looking into lsjs, but am hoping to get some opinions on it first, but it does look promising with it's localstorage capabilities – user834418 Feb 20 '13 at 18:09

4 Answers4

4

By "dynamic code loading," do you mean something like this?

You may want to try (listed in order of size):

Full disclosure: I wrote amdlite. It passes all relevant unit tests, but has not seen much real-world use. If you try it and discover anything wrong with it, please file an issue.

Community
  • 1
  • 1
Dagg Nabbit
  • 75,346
  • 19
  • 113
  • 141
  • Your amdlite — it's actually looks great. By far, the smallest amd loader I have ever saw. – oddy Sep 24 '14 at 03:06
  • 1
    @oddy, thanks! It's a bit different from other loaders, because it's an "eager loader." This means as soon as a module definition is encountered, its dependencies begin loading, and as soon as the dependency chain is ready, the factory will run. So there is no need for a `require` function, you can just use `define` in the same way you'd use `require`. I should probably write a readme one of these days. – Dagg Nabbit Sep 24 '14 at 07:14
  • I have noticed that. Curl does not require to use require as well, so I recon it follows the same principle, but it weights wooping 9 kb (compared to amdlite). And amdlite worked like a charm as a drop in replacement. Really great job, thank you for this tiny loader! – oddy Sep 24 '14 at 23:08
1

I believe this is reasonably close to the AMD spec, and at 960 bytes minified (not counting the spurious newline at the end) might grab the top spot.

https://github.com/MaxMotovilov/eeMD

  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – thewaywewere Jun 08 '17 at 00:51
  • 1
    I am not sure what to add to my comment -- the original poster was asking for links to AMD loaders, and that's what I provided along with the information pertinent to the primary requirement (i.e. size). Since I own the repository linked to, I can also be reasonably sure of it not going away. – Max Motovilov Jun 09 '17 at 02:10
0

You might want to take a look at this lockandload AMD loader which I wrote to support some of my own projects:

  • Gzipped but not minified it's around 859 bytes.

  • Not gzipped and not minified it's around 1520 bytes.

  • It does not need polyfills, it runs on all browsers from IE10 and up.

  • It's RequireJS compatible (and thus supports cyclic dependencies).

  • It supports anonymous modules.

  • It supports loading legacy javascript as well.

  • It supports legacy jQuery code.

  • It integrates Google Tag Manager (GTM).

BuGless
  • 159
  • 1
  • 4
-1

In addition to Dagg Nabbit's answer, I have published the AMD code that I wrote and use for my own projects.

It's about as tiny and simple that you can make this sort of component. If you want to roll your own, it serves as a great starting point that you can retool for whatever purpose you need.

Note: this does not conform to any sort of specification or standard. It's just meant to be fast and tiny.

Community
  • 1
  • 1
TikiTDO
  • 63
  • 7
  • By 'the above' you mean the accepted answer? Better put a link there, or be more specific e.g the answer of User X – Athafoud Mar 28 '16 at 09:55
  • This is none of the things OP asked for: this is first of all not an AMD loader at all - and secondly, it does not support dynamic loading. – mindplay.dk Dec 09 '16 at 07:50
  • By the strict defintion of asynchronous module definition, which you too could know if you bothered to look it up, it is very much an AMD. It allows the asyncronous definition and loading of code. What it does not do is meet the AMD.js specification. – TikiTDO Dec 10 '16 at 14:12
  • Also, as the other answer pointed out, the asker did not describe what he meant by "dynamic loading" which is a fairly generic term in its own right, similar to how AMD is quite generic. In short your only purpose here seems to be to complain that I don't use the terms in the exact specific way that you do. – TikiTDO Dec 10 '16 at 14:17