Coder Social home page Coder Social logo

g.js's People

Contributors

j1anb1n avatar

Stargazers

anonx avatar 张艳 avatar Allen Luo avatar Ding Yi avatar niphor avatar  avatar

Watchers

 avatar James Cloos avatar Ding Yi avatar  avatar  avatar

g.js's Issues

取消关于合并JS的配置项

目的:

加载合并文件的时候能够不需要知道合并配置,就能避免零散请求.

原理描述

在老的版本中,我们当我们需要加载某个合并文件的时候需要提前知道当前合并文件的所有子文件,以便将这些子文件标记为FETCHING的状态。
这样可以避免之后再加载子文件时发起零散的请求,主要有两种情景:
1,手动加载子文件
2,子文件依赖链的处理可能导致加载其他子文件

例如:

配置:

G.config({
    combine: {
        "x.cmb.js": ["a.js", "b.js", "c.js"]
    }
});

合并文件内容:

define('a.js', ['b.js', 'c.js'], function () {...});
define('b.js', [], function () {...});
define('c.js', [], function () {...});

情景1: 手动加载子文件

G.use(['x.cmb.js']);
G.use('a.js'); // 手动加载某个子文件
  • 如果有config存在:
    我们可以提前预知子文件列表,并提前标记状态为FETCHING。可以避免子文件的零散加载。否则文件会被分散加载。
  • 如果没有config存在:
    可以修改代码为:
G.use(['x.cmb.js'], function () {
    G.use('a.js', function () {
        ...
    });
})

情景2: 依赖链处理

情景2就是合并文件中的内容描述的那样,当处理a.js的依赖链的时候,b.js, c.js会被作为依赖项发起请求.

  • 如果有config存在:
    我们可以提前预知子文件列表,并提前标记状态为FETCHING。可以避免子文件的零散加载。否则文件会被分散加载。
  • 如果没有config存在:
    当执行define时,仅记录下依赖项,而不发起请求.当interactiveScript触发onload事件时一起发起请求.(顺便可以在这里处理动态合并).

使用时感受到的几个问题

@j1anb1n.

G.use 的第一个参数必须是数组

G.use(['some.js']);

第一个参数必须是数组,我觉得应该支持传入 string,毕竟有时候是只需要 use 一个 js 文件的

G.use 一个 cmb 文件后如何获得 cmb 中的各个 module?

G.use(['a.cmb.js'], function(a) {
    // how to access modules in a.cmb.js?
});

a.cmb.js:

a.js
b.js
c.js

如何获取 a, b 和 c 呢?考虑传一个 Object 进来?类似于:

G.use(['a.cmb.js'], function(module) {
    var a = module['a.js'],
        b = module['b.js'],
        c = module['c.js'];
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.