javascript – 如何通过CDN使用Dojo时加载自定义AMD模块?

前端之家收集整理的这篇文章主要介绍了javascript – 如何通过CDN使用Dojo时加载自定义AMD模块?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用谷歌的CDN,并试图加载我自己的AMD模块使用他们的装载机.我知道我在做错事,但我被卡住了.有任何想法吗?
<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.7.0/dojo/dojo.js" 
            type="text/javascript" data-dojo-config="async:true,parSEOnLoad:true"></script>
    <script type="text/javascript">
        require(["dojo/_base/kernel","dojo/_base/loader","dojo/parser"],function(dojo){
            dojo.registerModulePath("pgGallery","http://127.0.0.1:8080/js");
        });
        require(["pgGallery/Message"],function(m){
            m.success("foo");
        });
    </script>

http://127.0.0.1:8080/js/Message.js是模块的位置.

解决方法

我在这里找到了如何做: http://dojotoolkit.org/reference-guide/quickstart/cross-domain.html在“使用CDN与本地模块”下.

页面的示例:

<script type="text/javascript">
    var dojoConfig = {
        async: true,packages: [
            {
                name: "my",location: "/absolute/path/to/local/modules"
            }
        ]
    };
</script>

<!-- Bootstrap Dojo From Google's CDN -->
<!-- removing the protocol from src url auto detects if current page is served via http or https and also loads the dojo resources from matching protocol -->
<script
    type="text/javascript"
    src="//ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js">
</script>

<script type="text/javascript">
    require(["my/FooModule"],function(FooModule){
        // ...
    });
</script>
原文链接:https://www.f2er.com/js/152146.html

猜你在找的JavaScript相关文章