I am using google's CDN and also trying to load my own AMD modules using their loader. I know I'm doing something wrong but I'm stuck. Any ideas?
<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 is the location of the module.
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.