How to load custom AMD modules when using Dojo via CDN?

六月ゝ 毕业季﹏ 提交于 2019-12-05 01:39:51
chotchki

I figured out how to do it here: http://dojotoolkit.org/reference-guide/quickstart/cross-domain.html under "Using CDN with Local modules".

The example from the page:

<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>

Another option that is supposed to work, which I am using is this. Note the ".js". Somehow the loader treats that differently.

require(["pgGallery/Message.js"], function(m){
        m.success("foo");
    });

See: http://dojotoolkit.org/reference-guide/1.8/loader/amd.html.

If moduleId begins with a protocol (for example, “http:”) or a forward-slash, or ends with a ”.js” suffix, assume the request is for an arbitrary chunk of JavaScript, not a module.

What I do not know is if this is best practice or not.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!