语言: JavaScript


A RequireJS plugin for lazy loading AMD modules packaged with r.js, automatically splitting packaged code in bundles,… (中文)


一个RequireJS插件,用于延迟加载与r.js一起打包的AMD模块,自动拆分打包 捆绑包中的代码,仅在代码更改时缓存捆绑包,以及定义模块元数据 和Javascript应用程序中的模块发现。



define(["lazy!modules/m1", "lazy!modules/m2", "lazy!text!templates/faq.html"],
function(m1, m2, faq) {

在最简单的情况下,模块main,m1,m2没有共同的依赖关系,Require-Lazy 构建脚本将创建4个单独的包。一个将包含main.js和lazy.js,一个m1.js 及其所有依赖项,一个m2.js及其所有依赖项和一个text.js和faq.html。



v request参数是构建文件内容的哈希值,用作缓存破坏程序。

懒惰的插件将用惰性存根替换每个惰性模块。存根(当时) 一个方法,get()返回真实模块的promise:

m1.get().done(function(m) {
    // here m is the real module

可以在examples / simple中找到更详细的讨论和示例项目设置 目录。



  • Node.js(构建目标应用程序并运行示例所必需的)
  • requirejs
  • 杏仁
  • lazyload
  • r.js
  • node.extend
  • jQuery(依赖于Deferred实现,可以通过适配器使用任何其他库;请参阅此测试以获取示例)
  • expressjs(用于提供示例)


这个项目正在开发中。虽然很多事情都有效,但预计会有所改善 还有更多人不会。更糟糕的是,有些东西可能无法按预期工作。而且代码是 尚未经过彻底测试。

但是,我对目前的工作方式非常满意;我不希望任何激进的API /用法更改。 这意味着该项目可以被认为是相当稳定的API /使用方式。


本文使用googletrans自动翻译,仅供参考, 原文来自


A RequireJS plugin for lazy loading AMD modules packaged with r.js, automatically splitting packaged
code in bundles, cache-breaking the bundles only when the code changes, and defining module metadata
and module discovery in Javascript applications.

Quick Example

Main module (main.js):

define(["lazy!modules/m1", "lazy!modules/m2", "lazy!text!templates/faq.html"],
function(m1, m2, faq) {

In the simplest case where the modules main, m1, m2 have no common dependencies, Require-Lazy
build scripts will create 4 separate bundles. One will contain main.js and lazy.js, one m1.js
and all its dependencies, one m2.js and all its dependencies and one text.js and faq.html.

The URL for each module will look like:


The v request parameter is a hash of the contents of the built file, used as cache-breaker.

The lazy plugin will replace each lazy module with a lazy stub. The stub has (for the time)
one method, get() that returns a promise for the real module:

m1.get().done(function(m) {
    // here m is the real module

A more detailed discussion and an example project setup can be found in the examples/simple


This project requires, includes, or uses code from:

Development Status

This project is an idea under development. While many things work, it is expected
that many more will not. Even worse, some things may not work as expected. Moreover the code is
not thoroughly tested yet.

However, I am quite satisfied with how things work at the moment; I do not expect any radical API/usage changes.
This means that this project can be considered fairly stable API/usage-wise.

Ideas, criticism, comments, code contributions are all welcome!