53

Bootstrap 分布在 CDN 中

http://www.bootstrapcdn.com/

  • 是否可以使用 Require.JS 2.x(垫片或原生 AMD)加载引导程序?

  • 如何使用 Require.js 直接从 CDN URL 加载 Bootstrap 或任何缩小的 JS

4

1 回答 1

100
requirejs.config({
    appDir: ".",
    baseUrl: "js",
    paths: { 
        /* Load jquery from google cdn. On fail, load local file. */
        'jquery': ['//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min', 'libs/jquery-min'],
        /* Load bootstrap from cdn. On fail, load local file. */
        'bootstrap': ['//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.', 'libs/bootstrap-min']
    },
    shim: {
        /* Set bootstrap dependencies (just jQuery) */
        'bootstrap' : ['jquery']
    }
});

require(['jquery', 'bootstrap'], function($) {
    console.log("Loaded :)");    
    return {};
});
于 2012-11-21T17:33:08.320 回答