使用Require.js从CDN加载Bootstrap [英] Loading Bootstrap from CDN with Require.js

查看:99
本文介绍了使用Require.js从CDN加载Bootstrap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

引导程序在CDN中分发

Bootstrap is distributed in CDN in

http:// www.bootstrapcdn.com/


  • 是否可以用Require.JS 2.x加载Bootstrap或原生AMD)?

  • Is it possible to load Bootstrap with Require.JS 2.x (shimmed or native AMD)?

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

How it is possible to load Bootstrap, or any minified JS, directly from CDN URL with Require.js

推荐答案

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 {};
});

这篇关于使用Require.js从CDN加载Bootstrap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆